note 116925 deleted from language.variables by cmb
| From: | cmb@php.net | Date: | Mon, 05 Nov 2018 12:52:37 +0000 |
| Subject: | note 116925 deleted from language.variables by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209626@lists.php.net to get a copy of this message | ||
Note Submitter: Kubo2
----
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'}
);
?>