Req #65919 [Opn->Wfx]: Method of Only Execute Functions in an Array Variable When Requested
| From: | requinix@php.net | Date: | Wed, 16 Oct 2013 20:03:01 +0000 |
| Subject: | Req #65919 [Opn->Wfx]: Method of Only Execute Functions in an Array Variable When Requested | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182321@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65919&edit=1
ID: 65919
Updated by: requinix@php.net
Reported by: admin at skid dot pro
Summary: Method of Only Execute Functions in an Array
Variable When Requested
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Arrays related
Operating System: Irrelevent
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-10-16 19:37:03] admin at skid dot pro
Description:
------------
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'
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65919&edit=1