|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-04-25 18:11 UTC] helly@php.net
[2004-04-26 11:25 UTC] wf at bitplan dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 12:00:01 2025 UTC |
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: