Re: behaviour of static calls to regular methods
| From: | Johannes Schlueter | Date: | Mon, 21 Jun 2004 16:34:45 +0000 |
| Subject: | Re: behaviour of static calls to regular methods | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-10693@lists.php.net to get a copy of this message | ||
Hi,
yes, afaik it's intentional. This was made for making parent::foo() work.
Here's a shorter (at least a bit shorter *g*) example of this behavior:
<?php
class foo {
function a() {
bar::b();
}
}
class bar {
function b() {
var_dump($this);
}
}
$foo = new foo();
$foo->a(); // Calls bar::b()
?>
Prints:
object(foo)#1 (0) {
}
So in a static call $this holds the instance of the calling object.
johannes
Ard Biesheuvel wrote:
>
> Is the fact that the following code works intentional ?
>
> class S {
> function func() {
> A::meth();
> }
> }
>
> class A {
> private $bar;
>
> function meth() {
> $this->bar="bar";
> }
>
> function func() {
> S::func();
> echo "$this->bar\n";
>
> }
> }
>
>
> $a = new A;
> $a->func();
>
> ... so A::$this is accessed through two static calls to different classes.
>