note 65314 added to language.variables.variable
| From: | FlorianSonner at osu1 dot php dot net | Date: | Fri, 28 Apr 2006 15:44:37 +0000 |
| Subject: | note 65314 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-109996@lists.php.net to get a copy of this message | ||
If you have to access to variable variables in a method (or function) you can simply use the
workaround below. That little example should print a list with all variables in $_POST. And if you
want to access to the elements of the array, take a look at Shawn Beltz (thank you for the basic
idea ;-) ) Note.
<?php
class Foo
{
private $superglobal = 'POST';
public function Bar()
{
var_dump(eval("return \$_$this->superglobal;"));
}
}
$f = new Foo();
$f->Bar();
?>
----
Server IP: 217.160.72.57
Probable Submitter: 84.142.183.199
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- http://master.php.net/note/edit/65314
Del: integrated -- http://master.php.net/note/delete/65314/integrated
Del: useless -- http://master.php.net/note/delete/65314/useless
Del: bad code -- http://master.php.net/note/delete/65314/bad+code
Del: spam -- http://master.php.net/note/delete/65314/spam
Del: non-english -- http://master.php.net/note/delete/65314/non-english
Del: in docs -- http://master.php.net/note/delete/65314/in+docs
Del: other reasons-- http://master.php.net/note/delete/65314
Reject -- http://master.php.net/note/reject/65314
Search -- http://master.php.net/manage/user-notes.php