Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PATCH] Bug #53727 Inconsistent behavior of is_subclass_of with interfaces [RSS Feed]

#1 Jan. 13, 2011 00:16:51

Marc E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PATCH] Bug #53727 Inconsistent behavior of is_subclass_of with interfaces


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
trueIndex: 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

Offline

  • Root
  • » PHP
  • » [PATCH] Bug #53727 Inconsistent behavior of is_subclass_of with interfaces [RSS Feed]

Board footer

Moderator control

Enjoy the 24th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support