Re: Re: Static weirdness..
| From: | Hans Lellelid | Date: | Thu, 19 Feb 2004 15:14:53 +0000 |
| Subject: | Re: Re: Static weirdness.. | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7998@lists.php.net to get a copy of this message | ||
Timm Friebe wrote:
On Wed, 2004-02-18 at 18:40, Hans Lellelid wrote:Yeah, I'm sure there's a way to get something like that to work also. I'm not sure that's prefereable to call_user_func(), honestly -- and it doesn't get around the basic problem which is that calling code needs to know whether methods are static. I guess I'm not sure why this is necessary ... As Hartmut & Lukas mention, I don't know why the class consumer *needs* to know that it's static. Clearly internally there should be no possibility of referencing $this. Also in my example the entire class is static -- i.e. all methods are static -- but what about cases where one or two methods in a class are static. Now $a->methodName() will work for most but all of a sudden you have to do $a::staticMethodName() for the static members. What I see as the workaround is creating static methods that aren't marked as static -- e.g. that would address the issue in my example above. I think that's a lot worse than allowing invocation of static methods using instances, however, because I do want developers who read the API docs to know these are static functions. Hansforeach($entities as $ent) { $peer = $ent->getPeer(); // e.g. might be BookPeer $peer->doSelect(new Criteria()); //static: BookPeer::doSelect() }$m= new Reflection_Method($ent->getPeer(), 'doSelect'); $m->invoke(NULL, new Criteria()); /* untested */