|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65919 Method of Only Execute Functions in an Array Variable When Requested
Submitted: 2013-10-16 19:37 UTC Modified: 2013-10-16 20:03 UTC
From: admin at skid dot pro Assigned:
Status: Wont fix Package: Arrays related
PHP Version: Irrelevant OS: Irrelevent
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: admin at skid dot pro
New email:
PHP Version: OS:


 [2013-10-16 19:37 UTC] admin at skid dot pro
I seem to be pushed into a wall where I require an array to only execute functions (in-line and in general) in an array value if it's requested. I realize that I may be able to do this via OOP and ArrayAccess, however I find it's not actually able to provide me with what I need. See the test script for an example of what I'm aiming for.

Test script:
$var = "Before";

function getVar(){
    global $var;
    return $var;

$array = Array(
    "variableA" => "A: " . getVar(),
    "variableB" ~> "B: " . getVar() //~> in place of =>

$var = "After";

echo $array['variableA']; //Would echo 'A: Before'
echo $array['variableB']; //Would echo 'B: After'

Expected result:
$array['variableA'] Would equal 'A: Before'
$array['variableB'] Would equal 'B: After'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-16 20:03 UTC]
-Status: Open +Status: Wont fix
 [2013-10-16 20:03 UTC]
There are better mechanisms available than some sort of delayed evaluation thing:
a) A class to behave as the registry that $array seems to be, which can have __get/set and ArrayAccess methods
b) A function to get the value of variableB (instead of using $array)
c) A setter function that sets $var (rather than setting $var directly) and at the same time variableB

Delayed evaluation can at the very least screw up optimizations, lead to confusing bugs, and complicate debugging.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 08 11:01:26 2023 UTC