note 11675 added to Variable variables
| From: | helloracecar at not-quite dot here | Date: | Thu, 01 Mar 2001 22:58:07 +0000 |
| Subject: | note 11675 added to Variable variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11742@lists.php.net to get a copy of this message | ||
here's some strange behavior... if you run:
$arrayvar = array();
$regvar = 'arrayvar["idx"]';
$$regvar = 'Hello!';
then
$regvar is 'arrayvar["idx"]',
$$regvar is 'Hello!',
and
${arrayvar["idx"]} is "Hello!",
but $arrayvar["idx"] is empty!
SO, what's actually happening is that PHP has assigned a variable called
'arrayvar["idx"]', but (because it was assigned in a variable variable)
hasn't parsed it for brackets in order to make it an array! And when you try to use the
variable directly, it DOES parse for the brackets, therefore making the variable you intended to set
different from the one you actually set.
http://www.php.net/manual/en/language.variables.variable.php