note 98641 added to language.variables.variable
| From: | mason at osu1 dot php dot net | Date: | Mon, 28 Jun 2010 19:39:57 +0000 |
| Subject: | note 98641 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170530@lists.php.net to get a copy of this message | ||
PHP actually supports invoking a new instance of a class using a variable class name since at least
version 5.2
<?php
class Foo {
public function hello() {
echo 'Hello world!';
}
}
$my_foo = 'Foo';
$a = new $my_foo();
$a->hello(); //prints 'Hello world!'
?>
Additionally, you can access static methods and properties using variable class names, but only
since PHP 5.3
<?php
class Foo {
public static function hello() {
echo 'Hello world!';
}
}
$my_foo = 'Foo';
$my_foo::hello(); //prints 'Hello world!'
?>
----
Server IP: 69.147.83.197
Probable Submitter: 208.65.181.179
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- https://master.php.net/note/edit/98641
Del: integrated -- https://master.php.net/note/delete/98641/integrated
Del: useless -- https://master.php.net/note/delete/98641/useless
Del: bad code -- https://master.php.net/note/delete/98641/bad+code
Del: spam -- https://master.php.net/note/delete/98641/spam
Del: non-english -- https://master.php.net/note/delete/98641/non-english
Del: in docs -- https://master.php.net/note/delete/98641/in+docs
Del: other reasons-- https://master.php.net/note/delete/98641
Reject -- https://master.php.net/note/reject/98641
Search -- https://master.php.net/manage/user-notes.php