note 96738 added to language.oop5.overloading
| From: | tomfromhh at osu1 dot php dot net | Date: | Sat, 13 Mar 2010 12:53:07 +0000 |
| Subject: | note 96738 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166998@lists.php.net to get a copy of this message | ||
Singlton attempt with __callStatic:
<?php
class Singleton {
private static $__instance = null;
private function __construct() {
}
/**
* Alternative to get rid of the isset-check in __callStatic
*
* @static
* @access public
*/
public static function setup() {
if(!isset(self::$__instance)) {
self::$__instance = new self;
} else { /** Error */}
}
public static function __callStatic($name, $arguments) {
if(!isset(self::$__instance)) {
self::$__instance = new self;
}
return call_user_func_array(array(self::$__instance, "_" . $name), $arguments);
}
public function _foo($bar) {
echo $bar;
}
}
Singleton::foo("bar");
?>
while using PHP Strict Standards the underscored method calls are sadly required. Seems like the
interpreter got problems overloading object calls with static calls. Any improvements/ideas?
----
Server IP: 69.147.83.197
Probable Submitter: 78.54.59.54
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/96738
Del: integrated -- https://master.php.net/note/delete/96738/integrated
Del: useless -- https://master.php.net/note/delete/96738/useless
Del: bad code -- https://master.php.net/note/delete/96738/bad+code
Del: spam -- https://master.php.net/note/delete/96738/spam
Del: non-english -- https://master.php.net/note/delete/96738/non-english
Del: in docs -- https://master.php.net/note/delete/96738/in+docs
Del: other reasons-- https://master.php.net/note/delete/96738
Reject -- https://master.php.net/note/reject/96738
Search -- https://master.php.net/manage/user-notes.php