Memory App
 



Building memory bonds
Php  >     ZCE 5.3  |  Patterns  |  Modern Php Php   >   Variables   >   Variable variable


$name = 'foo';
$name = 'bar';

echo $foo; // Displays 'bar'
It is possible to create variables whose names do not follow the variables constraints.

$name = '123';
$$name = '456';

echo ${'123'}; // output 456
Variable variables are a very powerful tool, and should be used with extreme care. Their improper use can lead to some significant security issues. A technique similar to variable variables can also be used to hold function names inside a variable:

function myFunc() {
    echo 'myFunc!';
}

$f = 'myFunc';
$f();  // output myFunc!