#26747 [Opn]: Variable Variables don't work properly with Arrays
| From: | japril78 at hotmail dot com | Date: | Tue, 30 Dec 2003 09:29:12 +0000 |
| Subject: | #26747 [Opn]: Variable Variables don't work properly with Arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-52604@lists.php.net to get a copy of this message | ||
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 = '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
Previous Comments:
------------------------------------------------------------------------
[2003-12-30 04:27:43] japril78 at hotmail dot com
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
------------------------------------------------------------------------
[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