note 116925 added to language.variables

From: Date: Sun, 22 Mar 2015 11:10:22 +0000
Subject: note 116925 added to language.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-202007@lists.php.net to get a copy of this message
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'} ); ?> ---- Server IP: 89.187.142.233 Probable Submitter: 62.197.243.253 ---- Manual Page -- http://php.net/manual/en/language.variables.php Edit -- https://master.php.net/note/edit/116925 Del: integrated -- https://master.php.net/note/delete/116925/integrated Del: useless -- https://master.php.net/note/delete/116925/useless Del: bad code -- https://master.php.net/note/delete/116925/bad+code Del: spam -- https://master.php.net/note/delete/116925/spam Del: non-english -- https://master.php.net/note/delete/116925/non-english Del: in docs -- https://master.php.net/note/delete/116925/in+docs Del: other reasons-- https://master.php.net/note/delete/116925 Reject -- https://master.php.net/note/reject/116925 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202007) next »