note 55617 added to language.oop5.overloading

From: Date: Tue, 09 Aug 2005 01:00:25 +0000
Subject: note 55617 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-93279@lists.php.net to get a copy of this message
I just wanted to share with the rest of you since I had not seen it posted yet that __call does not work as a static method. Consider a utility class that has all static methods on it where one or more of those methods are overloaded. The snippet below will not work until you remove the "static" keyword from the __call function declaration: class MyClass { public static _call($method, $args) { switch($method) { case "Load": if(count($args) == 1) $this->funcLoad1($args[0]); elseif(count($args) == 2) $this->funcLoad2($args[0],$args[1]); } } private static funcLoad1($userID) { //do something } private static funcLoad2($userID, $isActive) { //do something slightly different } } This means any class that wishes to "overload" methods in PHP must be instantiatable in some regard. I like to use a pattern whereby one of the participants is a utility class exposing only static functions which operates on data exposed from an "info" or state-bag class. This is still possible in PHP, I suppose. It just means I'll need to incur overhead to instantiate my utility classes as well. You CAN, by the way, call one static method from another using $this as I've done in the switch according to a "note" section on this page. http://us3.php.net/language.oop Again that may pre-suppose some level of instantiation for the class. ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55617 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55617&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55617&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55617&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55617&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55617&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55617&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55617&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93279) next »