#43914 [Opn->Bgs]: Invalid invocation of non-static class function
| From: | tony2001@php.net | Date: | Mon, 28 Jan 2008 23:31:57 +0000 |
| Subject: | #43914 [Opn->Bgs]: Invalid invocation of non-static class function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-121633@lists.php.net to get a copy of this message | ||
ID: 43914
Updated by: tony2001@php.net
Reported By: mo at modejong dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: WinXP
PHP Version: 5.2.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
>Use of a method call like CLASS::METHOD inside a class def does
>not mean the method being invoked is static.
Yes, it does.
Previous Comments:
------------------------------------------------------------------------
[2008-01-23 00:34:31] mo at modejong dot com
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 this bug report at http://bugs.php.net/?id=43914&edit=1