note 101121 added to language.oop5
| From: | LordAlan at gmail dot com | Date: | Sun, 28 Nov 2010 01:25:06 +0000 |
| Subject: | note 101121 added to language.oop5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174403@lists.php.net to get a copy of this message | ||
As of PHP 5.3, you can actually use a variable as the class name when calling a static method
(singleton pattern). The following now works:
<?php
class Dog
{
public static function bark()
{
echo "Woof!";
}
}
$class = 'Dog';
$action = 'bark';
$class::$action(); //outputs "Woof!"
?>
This example is from an article that touches on some of the new features in PHP 5.3 including
"dynamic static calls":
http://www.ibm.com/developerworks/opensource/library/os-php-5.3new1/
----
Server IP: 69.147.83.197
Probable Submitter: 74.76.87.133
----
Manual Page -- http://www.php.net/manual/en/language.oop5.php
Edit -- https://master.php.net/note/edit/101121
Del: integrated -- https://master.php.net/note/delete/101121/integrated
Del: useless -- https://master.php.net/note/delete/101121/useless
Del: bad code -- https://master.php.net/note/delete/101121/bad+code
Del: spam -- https://master.php.net/note/delete/101121/spam
Del: non-english -- https://master.php.net/note/delete/101121/non-english
Del: in docs -- https://master.php.net/note/delete/101121/in+docs
Del: other reasons-- https://master.php.net/note/delete/101121
Reject -- https://master.php.net/note/reject/101121
Search -- https://master.php.net/manage/user-notes.php