Voting

Please answer this simple SPAM challenge: seven minus zero?
(Example: nine)

The Note You're Voting On

Kubo2
2 years ago
Note that if you use runtime variable name recognition in your code, you are able to use any string as a variable name. Consider following code:

<?php

$varName
= 'foo with bar';
${
'foo with bar'} = 42;

// will output int(42)
var_dump($$varName);

?>

This can be useful for example when accessing a property of an object constructed from JSON:

<?php

$composerJson
= json_decode(file_get_contents(__DIR__ . '/composer.json'));

// would output sth. similar to: object(stdClass)#...
var_dump(
   
$composerJson->{'require-dev'}
);

?>

<< Back to user notes page

To Top