Re: Re: self:: vs this

From: Date: Fri, 11 May 2007 20:14:40 +0000
Subject: Re: Re: self:: vs this
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-254819@lists.php.net to get a copy of this message
M.Sokolewicz wrote:
Basically what you can remember here is: :: calls a property or method in a STATIC context (ie. without access to the object's (if any) actual properties) -> calls a propert or method in a DYNAMIC context (ie. WITH access to that specific object's collection of methods and properties).
While that's generally true, self::, parent::, ClassName:: and ParentClassName:: can all be used in both contexts when calling methods. Consider the following code: <?php class Foo { function bar() { var_dump(isset($this)); } } class Test extends Foo { function __construct() {
       self::bar();
       parent::bar();
       Foo::bar();
       Test::bar();
} } new Test; ?> At first glance these all appear to be static method calls, but $this is available in every case. Arpad

« previous php.general (#254819) next »