[nycphp-talk] __call() in php5?
Adam Maccabee Trachtenberg
adam at trachtenberg.com
Mon Feb 16 04:02:49 EST 2004
On Mon, 16 Feb 2004, jon baer wrote:
> $obj = new Obj2(); // extension of Obj1
> $obj->foo();
>
> if Obj1 has a __call() without the function foo() it will work but if Obj2
> contains foo() the method will run and stop, so __call() is never really
> "called" .. just trying to understand this method ... the __set() and
> __get() seem ok.
The __call() method is only invoked when PHP 5 can't find a method to
run. Since you've defined a foo() method in Obj2, __call() is not
invoked when you do $obj->foo(). (Or at least that's how it should
work.)
If you want to have both behaviors, then you need to do something like
this in Obj2:
function foo() {
parent::foo();
// new stuff for Obj2::foo()
}
The __call() method should also respect visibility levels, so if you
have a private function foo() in Obj1, and then make Obj2 extend Obj1,
then __call() *will* be invoked, since there's no longer a foo()
method in Obj2.
Of course, my answer would be a heck of a lot better if I saw some
code. Right now, I just have to guess at what you're trying to do. :)
-adam
--
adam at trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!
More information about the talk
mailing list