note 101121 deleted from language.oop5 by danbrown
| From: | danbrown@php.net | Date: | Sun, 28 Nov 2010 01:35:10 +0000 |
| Subject: | note 101121 deleted from language.oop5 by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174404@lists.php.net to get a copy of this message | ||
Note Submitter: LordAlan at gmail dot com
----
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/