|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-11-08 17:36 UTC] mp at webfactory dot de
Description:
------------
instanceof produces wrong results when the first operand is not an object instance but a class name or a string containing a class name.
Reproduce code:
---------------
var_dump(Iterator instanceof Traversable);
var_dump("Iterator" instanceof Traversable);
Expected result:
----------------
bool(true)
bool(true)
Actual result:
--------------
bool(false)
Fatal error: Invalid opcode 138/1/1. in ...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 10:00:01 2025 UTC |
Checked PHP 5.2.1-dev (cli) (built: Dec 13 2006 08:24:06). var_dump(Iterator instanceof Traversable) now returns false, also with non-builtin (userland) classes, but should be true. var_dump("Iterator" instanceof Traversable) now gives an fatal error "instanceof expects an object instance, constant given". It should accept the first operand as a string just like is_subclass_of does and check if the class named "Iterator" subclasses/implements the other operand. $x = "Iterator"; var_dump($x instanceof Traversable) returns false. If $x is not an object but a string it might want to behave like the former case (string constant)?