Hello, I have attached a patch to the following bug, but I believe the bug is incorrect...
If is_subclass_of() is used in conjunction with a interface it should always return false because it's not a class, it's an interface. Test: ------ 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"; Expected result: ---------------- false true false true Actual result: -------------- true true false true
Index: ext/standard/tests/class_object/is_subclass_of_variation_002.phpt =================================================================== --- ext/standard/tests/class_object/is_subclass_of_variation_002.phpt (revision 306670) +++ ext/standard/tests/class_object/is_subclass_of_variation_002.phpt (working copy) @@ -80,6 +80,15 @@ var_dump( is_subclass_of($object, $value) ); }; + +// Bug #53727 - Inconsistent behavior of is_subclass_of with interfaces +interface MyInterface {} +class ParentClass implements MyInterface { } +class ChildClass extends ParentClass { } +echo "\nBug #53727\n"; +echo (is_subclass_of('ChildClass', 'MyInterface') ? 'true' : 'false') . "\n"; +echo (is_subclass_of('ParentClass', 'MyInterface') ? 'true' : 'false') . "\n"; + echo "Done"; ?> --EXPECTF-- @@ -168,4 +177,8 @@ Arg value bool(false) + +Bug #53727 +false +false Done \ No newline at end of file Index: Zend/zend_builtin_functions.c =================================================================== --- Zend/zend_builtin_functions.c (revision 306670) +++ Zend/zend_builtin_functions.c (working copy) @@ -855,6 +855,9 @@ retval = 0; } else { if (only_subclass) { + if ((*ce)->ce_flags & ZEND_ACC_INTERFACE) { + RETURN_FALSE; + } if (!instance_ce) { instance_ce = Z_OBJCE_P(obj)->parent; } else {
Kind Regards Marc
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php