Edit report at http://bugs.php.net/bug.php?id=53727&edit=1
ID: 53727 Comment by: chris at cmbuckley dot co dot uk Reported by: mattknight at xymail dot co dot uk Summary: Inconsistent behavior of is_subclass_of with interfaces Status: Open Type: Bug Package: Class/Object related Operating System: Gentoo x86_64 PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: Apologies; I actually meant: false true false true Previous Comments: ------------------------------------------------------------------------ [2011-01-12 17:58:37] chris at cmbuckley dot co dot uk One could argue that the expected result is actually: true true false false since neither classes are technically "subclasses" of the interface. Either way, the actual behaviour is undesirable :-) ------------------------------------------------------------------------ [2011-01-12 17:08:59] mattknight at xymail dot co dot uk Description: ------------ is_subclass_of() can take a string as the first parameter, as well as a second string parameter of the class name. It will check to see whether a class with the name specified in the first parameter is a subclass of the class with the name specified in the second parameter. This logic, however, doesn't apply with interfaces. The function behaves as expected for classes that don't directly implement an interface, but won't recognise the interface on a class that does directly implement it. Test script: --------------- <?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"; Expected result: ---------------- true true true true Actual result: -------------- true true false true ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53727&edit=1