php.net |  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
50 - 1 = ?
Subscribe to this entry?

 
 [2013-10-16 19:37 UTC] 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'


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-16 20:03 UTC] requinix@php.net
-Status: Open +Status: Wont fix
 [2013-10-16 20:03 UTC] requinix@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 10:01:29 2024 UTC