|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-01-28 23:31 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 05:00:02 2025 UTC |
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.