note 82866 modified in language.variables.variable by danbrown

From: Date: Wed, 24 Jun 2009 16:14:27 +0000
Subject: note 82866 modified in language.variables.variable by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157372@lists.php.net to get a copy of this message
You can use eval() to get around the limitation on using variable variables to reference superglobal arrays. e.g.: <?php # this fails: function indir($name) { $moe = $$name; echo "<pre>"; print_r($moe); echo "</pre>"; } indir("_SERVER"); # this works :-) function indir($name) { $moe = eval("return \$$name;"); echo "<pre>"; print_r($moe); echo "</pre>"; } indir("_SERVER"); ?> --was-- You can use eval() to get around the limitation on using variable variables to reference superglobal arrays. e.g.: # this fails: function indir($name) { $moe = $$name; echo "<pre>"; print_r($moe); echo "</pre>"; } indir("_SERVER"); # this works :-) function indir($name) { $moe = eval("return \$$name;"); echo "<pre>"; print_r($moe); echo "</pre>"; } indir("_SERVER"); http://php.net/manual/en/language.variables.variable.php

« previous php.notes (#157372) next »