Fixed Bug#43926 (isInstance() isn't equivalent to instanceof operator)

This commit is contained in:
Felipe Pena 2008-01-30 10:27:28 +00:00
parent 240fa244c3
commit 8452585fc8
3 changed files with 39 additions and 1 deletions

1
NEWS
View File

@ -240,6 +240,7 @@ PHP NEWS
- Fixed PECL bug #11216 (crash in ZipArchive::addEmptyDir when a directory
already exists). (Pierre)
- Fixed bug #43926 (isInstance() isn't equivalent to instanceof operator). (Marcus)
- Fixed bug #42368 (Incorrect error message displayed by pg_escape_string).
(Ilia)
- Fixed bug #42365 (glob() crashes and/or accepts way too many flags).

View File

@ -3402,7 +3402,7 @@ ZEND_METHOD(reflection_class, isInstance)
return;
}
GET_REFLECTION_OBJECT_PTR(ce);
RETURN_BOOL(ce == Z_OBJCE_P(object));
RETURN_BOOL(HAS_CLASS_ENTRY(*object) && instanceof_function(Z_OBJCE_P(object), ce));
}
/* }}} */

View File

@ -0,0 +1,37 @@
--TEST--
Bug#43926 - isInstance() isn't equivalent to instanceof operator
--FILE--
<?php
class E {
}
class D extends E {
}
class A extends D {
}
class C extends A {
}
$ra = new ReflectionClass('A');
$rc = new ReflectionClass('C');
$rd = new ReflectionClass('D');
$re = new ReflectionClass('E');
$ca = $ra->newInstance();
$cc = $rc->newInstance();
$cd = $rd->newInstance();
$ce = $re->newInstance();
print("Is? A ". ($ra->isInstance($ca) ? 'true' : 'false') .", instanceof: ". (($ca instanceof A) ? 'true' : 'false') ."\n");
print("Is? C ". ($ra->isInstance($cc) ? 'true' : 'false') .", instanceof: ". (($ca instanceof C) ? 'true' : 'false') ."\n");
print("Is? D ". ($ra->isInstance($cd) ? 'true' : 'false') .", instanceof: ". (($ca instanceof D) ? 'true' : 'false') ."\n");
print("Is? E ". ($ra->isInstance($ce) ? 'true' : 'false') .", instanceof: ". (($ca instanceof E) ? 'true' : 'false') ."\n");
?>
--EXPECT--
Is? A true, instanceof: true
Is? C false, instanceof: false
Is? D true, instanceof: true
Is? E true, instanceof: true