php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39435 wrong instanceof results
Submitted: 2006-11-08 17:36 UTC Modified: 2006-12-13 15:22 UTC
From: mp at webfactory dot de Assigned: pollita (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.2.0 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mp at webfactory dot de
New email:
PHP Version: OS:

 

 [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 ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-08 18:26 UTC] johannes@php.net
Sara should have a patch as soon as she gets online
 [2006-12-12 23:26 UTC] pollita@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

This has been changed to throw a proper error message rather than the uninformative one given.  Perhaps in future versions this can be changed to allow constant strings giving the expected output, but not currently.

 [2006-12-13 08:40 UTC] mp at webfactory dot de
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)?
 [2006-12-13 15:22 UTC] iliaa@php.net
The function needs to be passed an object not a name of an 
object.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC