Alex Rivera | Logout

Is this a php variable variable bug?

Asked 2010-07-23T13:07:15.260
14

Is there a logical explanation to this?

<?php  
$$a = 'hello world';  
echo $$a; //displays hello world  
echo $$aa; //displays hello world  
echo $$aaa; //displays hello world  
?>
Edit
Report

1 Answer

1

You are not getting it right, consider this:

$a = 'hello';
$hello = "hello again";
echo $$a;

Output:

hello again

In your case, you have not set the value of following variables, so it outputs the same.

Explanation:

When you do $$a, it means:

$                           $a;
^                            ^
$ used for php vars         means a's value that is hello

So it becomes:

$hello

Whose value is:

hello again
answered 2010-07-23T13:14:31.950

Your Answer