Patch fix-is_subclass_of-PHP_5_3.diff for Class/Object related Bug #53727
Patch version 2011-06-30 22:33 UTC
Return to Bug #53727 |
Download this patch
Patch Revisions:
Developer: ralph@smashlabs.com
:100755 100755 a074194... 0a01eb7... M Zend/tests/is_a.phpt
:000000 100755 0000000... b240b3f... A Zend/tests/is_subclass_of.phpt
:100644 100644 6888b7f... 4430ef7... M Zend/zend_builtin_functions.c
diff --git a/Zend/tests/is_a.phpt b/Zend/tests/is_a.phpt
index a074194..0a01eb7 100755
--- a/Zend/tests/is_a.phpt
+++ b/Zend/tests/is_a.phpt
@@ -38,6 +38,6 @@ bool(true)
bool(false)
bool(false)
bool(true)
-bool(false)
+bool(true)
AUTOLOAD 'X1'
bool(false)
diff --git a/Zend/tests/is_subclass_of.phpt b/Zend/tests/is_subclass_of.phpt
new file mode 100755
index 0000000..b240b3f
--- /dev/null
+++ b/Zend/tests/is_subclass_of.phpt
@@ -0,0 +1,28 @@
+--TEST--
+is_subclass_of() with class names for target and test should work with interfaces
+--INI--
+error_reporting=14335
+--FILE--
+<?php
+interface A {}
+class B implements A {}
+class C extends B {}
+
+var_dump(is_subclass_of('B', 'B'));
+var_dump(is_subclass_of(new B, 'B'));
+var_dump(is_subclass_of('B', 'A')); // @see https://bugs.php.net/bug.php?id=53727
+var_dump(is_subclass_of(new B, 'A')); // @see https://bugs.php.net/bug.php?id=53727
+var_dump(is_subclass_of('C', 'B'));
+var_dump(is_subclass_of(new C, 'B'));
+var_dump(is_subclass_of('C', 'A'));
+var_dump(is_subclass_of(new C, 'A'));
+?>
+--EXPECT--
+bool(false)
+bool(false)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 6888b7f..4430ef7 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -844,10 +844,12 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass)
retval = 0;
} else {
if (only_subclass) {
- if (!instance_ce) {
- instance_ce = Z_OBJCE_P(obj)->parent;
- } else {
- instance_ce = instance_ce->parent;
+ if (!instance_ce && Z_TYPE_P(obj) == IS_OBJECT) {
+ instance_ce = Z_OBJCE_P(obj);
+ }
+ if (instance_ce && instance_ce->name == (*ce)->name) {
+ // return here if the class entry names are the same
+ RETURN_FALSE;
}
} else {
instance_ce = Z_OBJCE_P(obj);
|