note 78059 modified in language.oop5.overloading by danbrown

From: Date: Fri, 14 Nov 2008 17:13:54 +0000
Subject: note 78059 modified in language.oop5.overloading by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146540@lists.php.net to get a copy of this message
Let us look at the following example: <?php class objDriver { private $value; public function __construct() { $value = 1; } public function doSomething($parameterList) { //We make actions with the value } } class WantStaticCall { private static $objectList; private function __construct() public static function init() { self::$objectList = array(); } public static function register($alias) { self::$objectList[$alias] = new objDriver(); } public static function __call($method, $arguments) { $alias = $arguments[0]; array_shift($arguments); call_user_method($method, self::$objectList[$alias], $arguments); } } // The deal here is to use following code: WantStaticCall::register('logger'); WantStaticCall::doSomething('logger', $argumentList); // and we will make objDriver to call his doSomething function with arguments // $argumentList. This is not common pattern but very usefull in some cases. // The problem here is that __call() cannot be static, Is there a way to work it around ?> --was-- Let us look at the following example: class objDriver { private $value; public function __construct() { $value = 1; } public function doSomething($parameterList) { //We make actions with the value } } class WantStaticCall { private static $objectList; private function __construct() public static function init() { self::$objectList = array(); } public static function register($alias) { self::$objectList[$alias] = new objDriver(); } public static function __call($method, $arguments) { $alias = $arguments[0]; array_shift($arguments); call_user_method($method, self::$objectList[$alias], $arguments); } } // The deal here is to use following code: WantStaticCall::register('logger'); WantStaticCall::doSomething('logger', $argumentList); // and we will make objDriver to call his doSomething function with arguments // $argumentList. This is not common pattern but very usefull in some cases. // The problem here is that __call() cannot be static, Is there a way to work it around http://php.net/manual/en/language.oop5.overloading.php

« previous php.notes (#146540) next »