note 55617 deleted from language.oop5.overloading by danielc
| From: | danielc@php.net | Date: | Thu, 03 Jul 2008 00:33:07 +0000 |
| Subject: | note 55617 deleted from language.oop5.overloading by danielc | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141095@lists.php.net to get a copy of this message | ||
Note Submitter: yuggoth23 at yahoo dot no dot spam dot com
Reason: 0
----
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.