Re: $this return calling object.

From: Date: Mon, 03 May 2004 16:19:17 +0000
Subject: Re: $this return calling object.
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-9643@lists.php.net to get a copy of this message
Ha Jochem, Jochem Maas wrote:
I have discovered behaviour which I imagine is not intended, name referencing $this in a static method that is called from a from the method of an instantiated. (see test code below.)
error_reporting(E_ALL & E_STRICT);
I'm sure you mean E_ALL | E_STRICT here ...
Class A {
    function test() {
        print_r( __CLASS__ );echo "\n";
        print_r( __METHOD__ );echo "\n";
        print_r( $this );echo "\n";
    }
} Class B { function test() { A::test(); } }
This behaviour is intentional for methods that are not defined as static. Also, as inherited methods are called using the parent:: syntax, this is the only way to call overridden methods without losing $this from scope along the way. -- Ard

« previous php.internals (#9643) next »