call_user_func, static calls, and $this
| From: | Brad Bulger | Date: | Wed, 13 Aug 2003 06:40:37 +0000 |
| Subject: | call_user_func, static calls, and $this | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-3873@lists.php.net to get a copy of this message | ||
this is old subject everyone is tired of i'm sure. but since large changes
have been made to call_user_func[_array] recently, i want to confirm:
if an object calls one of its methods ($thing->foo()), any static-type method calls made inside there - self::a(), parent::a(), fezbar::a() -
will have $this defined, pointing to original calling object.
self:: and parent:: are always relative to the containing class,
regardless of this.
two exceptions:
- the method is declared as 'static'; if so, $this is never set
- the method is called via call_user_func or call_user_func_array;
if so, $this is not set
the very last part seems like it *might* be a bug, or it might be a
decision - that call_user_func(array('class','function'),$arg)
will always force class::function() to behave as if declared statically.
that is a bit of a problem for self:: and parent:: but that is ok if it
is how it must be.
if anyone can say about this, it would be kind.
ps - i looked in old mail, sure this had been discussed - topic came up,
but nothing for sure, except introduction of 'static' to prevent $this,
which solves opposite problem :)