note 43995 deleted from language.variables by nlopess
| From: | nlopess@php.net | Date: | Tue, 13 Jul 2004 09:08:34 +0000 |
| Subject: | note 43995 deleted from language.variables by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73138@lists.php.net to get a copy of this message | ||
Note Submitter:
----
I was bored (nothing new :)) so I tried to code few extraodinary lines and somehow come with
something I could not explain at first. Here is the code:
<?php
$x= 'a';
$$x= 'b';
echo $x . "\n";
echo $a . "\n";
echo $$x . "\n";
$x= $$x ;
echo $x . "\n";
echo $a . "\n";
echo $$x . "\n";
?>
With out running the code can you predict what the output would be? Careful now!
-----------------------------------------------------------
The explanation:
$x= $$x // $x now points to the value b
The last line takes the value of $x which is 'b' and creates a variable variable $b
which is NULL.
Try adding this line of code before the last line: $b= 'Ah ha!'; and run the code again.
Regards,
drenintell