From:             mo at modejong dot com
Operating system: WinXP
PHP version:      5.2.5
PHP Bug Type:     Class/Object related
Bug description:  Invalid invocation of non-static class function

Description:
------------
PHP allows invocation of an instance method in a class that
is unrelated to the current class. I would think that the
correct thing to do in this case is to generate an error
at runtime when this specific case is detected.

Reproduce code:
---------------
class One {
  function foo() {
    $isnull = ($this == NULL) ? "TRUE" : "FALSE";
    $instanceof = ($this instanceof One) ? "TRUE" : "FALSE";
    print "One::foo is \$this null ($isnull) : is instanceof One
($instanceof)\n";
  }
}

class Two {
  function foo() {
    $isnull = ($this == NULL) ? "TRUE" : "FALSE";
    $instanceof = ($this instanceof Two) ? "TRUE" : "FALSE";
    print "Two::foo is \$this null ($isnull) : is instanceof Two
($instanceof)\n";
    return One::foo();
  }
}

$obj = new Two;
$obj->foo();


Expected result:
----------------
When executed, PHP prints:

Two::foo is $this null (FALSE) : is instanceof Two (TRUE)
One::foo is $this null (FALSE) : is instanceof One (FALSE)

It should generate an error here since Two is unrelated
to class One. This check should be done when invoking
the instance method, if the $this ref is not NULL then
the type of $this should be checked before the instance
method can be invoked in One.

I already read bug 42559, it seems to have been rejected
as "not a bug", but this issue is clearly a bug. Use of
a method call like CLASS::METHOD inside a class def does
not mean the method being invoked is static.


-- 
Edit bug report at http://bugs.php.net/?id=43914&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43914&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43914&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43914&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43914&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43914&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43914&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43914&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43914&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43914&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43914&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43914&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43914&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43914&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43914&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43914&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43914&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43914&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43914&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43914&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43914&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43914&r=mysqlcfg

Reply via email to