|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-12-30 04:26 UTC] japril78 at hotmail dot com
Description:
------------
The does not work as expected:
$array = array('one','two','three');
$arraypath = 'array[1]';
echo ${$arraypath};
Workaround:
$array = array('one','two','three');
$arraypath = 'myarray[1]';
eval('$value = $'.$arraypath.';');
echo $value;
BUT:
The workaround DOES NOT work inside a function.
Reproduce code:
---------------
$array = array('one','two','three');
$arraypath = 'array[1]';
$value = showit($arraypath);
function showit($arraypath)
{
eval('$value = $'.$arraypath.';');
echo $value; // Attempt #1
echo $$arraypath; // Attempt #2
echo ${$arraypath}; // Attempt #3
}
Expected result:
----------------
nothing
Actual result:
--------------
nothing
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 15:00:01 2025 UTC |
Description: ------------ This does not work as expected: $array = array('one','two','three'); $arraypath = 'array[1]'; echo ${$arraypath}; Workaround: $array = array('one','two','three'); $arraypath = 'myarray[1]'; eval('$value = $'.$arraypath.';'); echo $value; BUT: The workaround DOES NOT work inside a function. Reproduce code: --------------- $array = array('one','two','three'); $arraypath = 'array[1]'; $value = showit($arraypath); function showit($arraypath) { eval('$value = $'.$arraypath.';'); echo $value; // Attempt #1 echo $$arraypath; // Attempt #2 echo ${$arraypath}; // Attempt #3 } Expected result: ---------------- nothing Actual result: -------------- nothingDescription: ------------ This does not work as expected: $array = array('one','two','three'); $arraypath = 'array[1]'; echo ${$arraypath}; Workaround: $array = array('one','two','three'); $arraypath = 'array[1]'; eval('$value = $'.$arraypath.';'); echo $value; BUT: The workaround DOES NOT work inside a function. Reproduce code: --------------- $array = array('one','two','three'); $arraypath = 'array[1]'; $value = showit($arraypath); function showit($arraypath) { eval('$value = $'.$arraypath.';'); echo $value; // Attempt #1 echo $$arraypath; // Attempt #2 echo ${$arraypath}; // Attempt #3 } Expected result: ---------------- nothing Actual result: -------------- nothing