ID: 26747
User updated by: japril78 at hotmail dot com
Reported By: japril78 at hotmail dot com
Status: Open
Bug Type: Variables related
Operating System: WinXP Pro
PHP Version: 4.3.4
New Comment:
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:
--------------
nothing
Previous Comments:
------------------------------------------------------------------------
[2003-12-30 04:26:54] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26747&edit=1