]> granicus.if.org Git - php/commitdiff
Fixed Bug #43926 (isInstance() isn't equivalent to instanceof operator)
authorFelipe Pena <felipe@php.net>
Wed, 30 Jan 2008 10:54:41 +0000 (10:54 +0000)
committerFelipe Pena <felipe@php.net>
Wed, 30 Jan 2008 10:54:41 +0000 (10:54 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/bug43926.phpt [new file with mode: 0644]

index eb3dc483101df09796f854901f22617d0333dda0..82b2f3eda4581d8709f2a672be9859412b562120 100644 (file)
@@ -3481,7 +3481,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));
 }
 /* }}} */
 
diff --git a/ext/reflection/tests/bug43926.phpt b/ext/reflection/tests/bug43926.phpt
new file mode 100644 (file)
index 0000000..373f9f1
--- /dev/null
@@ -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
\ No newline at end of file