ID: 28145 Updated by: [EMAIL PROTECTED] Reported By: wf at bitplan dot com -Status: Open +Status: Bogus Bug Type: Class/Object related -Operating System: WindowsXP +Operating System: * -PHP Version: 5.0.0RC1 +PHP Version: 5* New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php In a statically called method $this is NULL and NULL representation is the empty string. Regarding #20089: In a stattically called method there cannot be a $this because it is a local variable generated by the engine. the behavior of PHP 4 is wrong and is there only because there simply was no way to implement it correct. One of the reasons it could not be done correct is the lack of real static methods. Previous Comments: ------------------------------------------------------------------------ [2004-04-25 17:26:01] wf at bitplan dot com Description: ------------ I am using PHP5 RC2 (couldn't yet select it - have downloaded it a few minutes ago ...) on Windows XP Professional with Apache2.0.49. This bug is similar to #20089 but I'm complaining more about the instanceof issue. The true fix is of course fixing #20089 first. Saying "This is not a bug" is not a good thing with the goal of better object orientation for PHP5 ... When calling an instance function ("->" needed) as a class function ("::") this should either be an error or instanceof for the given class should fail - it looks like a) instanceof returns "" instead of FALSE/0 when this is not the correct instance b) when calling an instance function of another class in a static way this should be an error Reproduce code: --------------- <?php class Foo { function __construct () { echo 'Generating a Foo object <br />'; } function getInstance () { return new Foo(); } function operation () { echo "Foo operation this is a ".get_Class($this)."<br>"; echo "This is a Foo: ".$this instanceof Foo."<br>"; } function baroperation () { Bar::operation(); } } class Bar { function __construct () { echo 'Generating a Bar object <br />'; } function getInstance () { return new Bar(); } function operation () { echo "Bar operation this is a ".get_Class($this)."<br>"; echo "This is a Bar: ".$this instanceof Bar."<br>"; } function fooOperation () { Foo::operation(); } } $foo = Foo::getInstance(); $bar = Bar::getInstance(); $foo->operation(); $bar->operation(); $foo->baroperation(); $bar->foooperation(); Foo::operation(); Bar::operation(); ?> Expected result: ---------------- Generating a Foo object Generating a Bar object Foo operation this is a Foo This is a Foo: 1 Bar operation this is a Bar This is a Bar: 1 error Bar operation but this is a Foo This is a Bar: 0 error Foo operation but this is a Bar This is a Foo: 0 Foo operation this is a nil This is a Foo: 0 Bar operation this is a nil This is a Bar: 0 Actual result: -------------- Generating a Foo object Generating a Bar object Foo operation this is a Foo This is a Foo: 1 Bar operation this is a Bar This is a Bar: 1 Bar operation this is a Foo This is a Bar: Foo operation this is a Bar This is a Foo: Foo operation this is a This is a Foo: Bar operation this is a This is a Bar: ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28145&edit=1
