note 94504 modified in language.oop5.paamayim-nekudotayim by danbrown

From: Date: Mon, 09 Nov 2009 16:24:51 +0000
Subject: note 94504 modified in language.oop5.paamayim-nekudotayim by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162663@lists.php.net to get a copy of this message
It's worth noting, that the mentioned variable can also be an object instance. This appears to be the easiest way to refer to a static function as high in the inheritance hierarchy as possible, as seen from the instance. I've encountered some odd behavior while using static::something() inside a non-static method. See the following example code: <?php class FooClass { public function testSelf() { return self::t(); } public function testThis() { return $this::t(); } public static function t() { return 'FooClass'; } function __toString() { return 'FooClass'; } } class BarClass extends FooClass { public static function t() { return 'BarClass'; } } $obj = new BarClass(); print_r(Array( $obj->testSelf(), $obj->testThis(), )); ?> which outputs: <pre> Array ( [0] => FooClass [1] => BarClass ) </pre> As you can see, __toString has no effect on any of this. Just in case you were wondering if perhaps this was the way it's done. --was-- It's worth nothing, that the mentioned variable can also be an object instance. This appears to be the easiest way to refer to a static function as high in the inheritance hierarchy as possible, as seen from the instance. I've encountered some odd behavior while using static::something() inside a non-static method. See the following example code: <?php class FooClass { public function testSelf() { return self::t(); } public function testThis() { return $this::t(); } public static function t() { return 'FooClass'; } function __toString() { return 'FooClass'; } } class BarClass extends FooClass { public static function t() { return 'BarClass'; } } $obj = new BarClass(); print_r(Array( $obj->testSelf(), $obj->testThis(), )); ?> which outputs: <pre> Array ( [0] => FooClass [1] => BarClass ) </pre> As you can see, __toString has no effect on any of this. Just in case you were wondering if perhaps this was the way it's done. --- http://www.ilikealot.com/ http://www.interpotential.com/ http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php

« previous php.notes (#162663) next »