]> granicus.if.org Git - php/commitdiff
Fixed bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
authorDmitry Stogov <dmitry@php.net>
Mon, 4 Jul 2011 14:55:39 +0000 (14:55 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 4 Jul 2011 14:55:39 +0000 (14:55 +0000)
NEWS
Zend/tests/bug53727.phpt [new file with mode: 0644]
Zend/tests/is_a.phpt
Zend/zend_builtin_functions.c
ext/standard/tests/class_object/is_a_variation_001.phpt

diff --git a/NEWS b/NEWS
index 13a004247ace32eac259b00a4b05e0e5afe53bd1..902a95c74f937615767ef670f3f58c64e9e9c1d1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,10 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2011, PHP 5.3.7
+- Core
+  . Fixed bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
+    (Ralph Schindler, Dmitry)
+
 - PDO DBlib:
   . Fixed bug #54329 (MSSql extension memory leak).
     (dotslashpok at gmail dot com)
diff --git a/Zend/tests/bug53727.phpt b/Zend/tests/bug53727.phpt
new file mode 100644 (file)
index 0000000..22cd523
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
+--FILE--
+<?php
+interface MyInterface {
+    const TEST_CONSTANT = true;
+}
+
+class ParentClass implements MyInterface { }
+
+class ChildClass extends ParentClass { }
+
+echo (is_subclass_of('ChildClass', 'MyInterface') ? 'true' : 'false') . "\n";
+echo (defined('ChildClass::TEST_CONSTANT') ? 'true' : 'false') . "\n";
+
+echo (is_subclass_of('ParentClass', 'MyInterface') ? 'true' : 'false') . "\n";
+echo (defined('ParentClass::TEST_CONSTANT') ? 'true' : 'false') . "\n";
+--EXPECT--
+true
+true
+true
+true
index a074194c4d446e290c57d03e9fdc6be3af05875e..0a01eb756e119f34eb49a847ca31c9c018f3ebe3 100755 (executable)
@@ -38,6 +38,6 @@ bool(true)
 bool(false)
 bool(false)
 bool(true)
-bool(false)
+bool(true)
 AUTOLOAD 'X1'
 bool(false)
index 6888b7f6625b27263d03e608677c6ee524dff28f..d0276091b64194967ee60db0d84143b1e0a4f254 100644 (file)
@@ -822,45 +822,26 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass)
                return;
        }
        
-       if (only_subclass && Z_TYPE_P(obj) == IS_STRING) {
+       if (Z_TYPE_P(obj) == IS_STRING) {
                zend_class_entry **the_ce;
                if (zend_lookup_class(Z_STRVAL_P(obj), Z_STRLEN_P(obj), &the_ce TSRMLS_CC) == FAILURE) {
                        zend_error(E_WARNING, "Unknown class passed as parameter");
                        RETURN_FALSE;
                }
                instance_ce = *the_ce;
-       } else if (Z_TYPE_P(obj) != IS_OBJECT) {
-               RETURN_FALSE;
+       } else if (Z_TYPE_P(obj) == IS_OBJECT && HAS_CLASS_ENTRY(*obj)) {
+               instance_ce = Z_OBJCE_P(obj);
        } else {
-               instance_ce = NULL;
-       }
-
-       /* TBI!! new object handlers */
-       if (Z_TYPE_P(obj) == IS_OBJECT && !HAS_CLASS_ENTRY(*obj)) {
                RETURN_FALSE;
        }
 
        if (zend_lookup_class_ex(class_name, class_name_len, 0, &ce TSRMLS_CC) == FAILURE) {
                retval = 0;
        } else {
-               if (only_subclass) {
-                       if (!instance_ce) {
-                               instance_ce = Z_OBJCE_P(obj)->parent;
-                       } else {
-                               instance_ce = instance_ce->parent;
-                       }
-               } else {
-                       instance_ce = Z_OBJCE_P(obj);
-               }
-
-               if (!instance_ce) {
-                       RETURN_FALSE;
-               }
-
-               if (instanceof_function(instance_ce, *ce TSRMLS_CC)) {
-                       retval = 1;
-               } else {
+               if (only_subclass && instance_ce == *ce) {
                        retval = 0;
+               } else {
+                       retval = instanceof_function(instance_ce, *ce TSRMLS_CC);
                }
        }
 
index d2d6ce24071f7da75223ca457cff5e3742fc9dec..1021544065bf8ac6fbb06e0672ed9aeacdf87cd7 100644 (file)
@@ -144,15 +144,23 @@ Arg value
 bool(false)
 
 Arg value  
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
 bool(false)
 
 Arg value  
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
 bool(false)
 
 Arg value string 
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
 bool(false)
 
 Arg value String 
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
 bool(false)
 
 Arg value