From:             wf at bitplan dot com
Operating system: WindowsXP
PHP version:      5.0.0RC1
PHP Bug Type:     Class/Object related
Bug description:  $this / instanceof issue with static calls of instance functions

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 bug report at http://bugs.php.net/?id=28145&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28145&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28145&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28145&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28145&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28145&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28145&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28145&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28145&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28145&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28145&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28145&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28145&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28145&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28145&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28145&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28145&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28145&r=float

Reply via email to