Skip to content

Commit 293f710

Browse files
committed
Fixed bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
1 parent 7fb6b5c commit 293f710

File tree

5 files changed

+41
-26
lines changed

5 files changed

+41
-26
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2011, PHP 5.3.7
4+
- Core
5+
. Fixed bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
6+
(Ralph Schindler, Dmitry)
7+
48
- PDO DBlib:
59
. Fixed bug #54329 (MSSql extension memory leak).
610
(dotslashpok at gmail dot com)

Zend/tests/bug53727.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
3+
--FILE--
4+
<?php
5+
interface MyInterface {
6+
const TEST_CONSTANT = true;
7+
}
8+
9+
class ParentClass implements MyInterface { }
10+
11+
class ChildClass extends ParentClass { }
12+
13+
echo (is_subclass_of('ChildClass', 'MyInterface') ? 'true' : 'false') . "\n";
14+
echo (defined('ChildClass::TEST_CONSTANT') ? 'true' : 'false') . "\n";
15+
16+
echo (is_subclass_of('ParentClass', 'MyInterface') ? 'true' : 'false') . "\n";
17+
echo (defined('ParentClass::TEST_CONSTANT') ? 'true' : 'false') . "\n";
18+
--EXPECT--
19+
true
20+
true
21+
true
22+
true

Zend/tests/is_a.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ bool(true)
3838
bool(false)
3939
bool(false)
4040
bool(true)
41-
bool(false)
41+
bool(true)
4242
AUTOLOAD 'X1'
4343
bool(false)

Zend/zend_builtin_functions.c

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -822,45 +822,26 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass)
822822
return;
823823
}
824824

825-
if (only_subclass && Z_TYPE_P(obj) == IS_STRING) {
825+
if (Z_TYPE_P(obj) == IS_STRING) {
826826
zend_class_entry **the_ce;
827827
if (zend_lookup_class(Z_STRVAL_P(obj), Z_STRLEN_P(obj), &the_ce TSRMLS_CC) == FAILURE) {
828828
zend_error(E_WARNING, "Unknown class passed as parameter");
829829
RETURN_FALSE;
830830
}
831831
instance_ce = *the_ce;
832-
} else if (Z_TYPE_P(obj) != IS_OBJECT) {
833-
RETURN_FALSE;
832+
} else if (Z_TYPE_P(obj) == IS_OBJECT && HAS_CLASS_ENTRY(*obj)) {
833+
instance_ce = Z_OBJCE_P(obj);
834834
} else {
835-
instance_ce = NULL;
836-
}
837-
838-
/* TBI!! new object handlers */
839-
if (Z_TYPE_P(obj) == IS_OBJECT && !HAS_CLASS_ENTRY(*obj)) {
840835
RETURN_FALSE;
841836
}
842837

843838
if (zend_lookup_class_ex(class_name, class_name_len, 0, &ce TSRMLS_CC) == FAILURE) {
844839
retval = 0;
845840
} else {
846-
if (only_subclass) {
847-
if (!instance_ce) {
848-
instance_ce = Z_OBJCE_P(obj)->parent;
849-
} else {
850-
instance_ce = instance_ce->parent;
851-
}
852-
} else {
853-
instance_ce = Z_OBJCE_P(obj);
854-
}
855-
856-
if (!instance_ce) {
857-
RETURN_FALSE;
858-
}
859-
860-
if (instanceof_function(instance_ce, *ce TSRMLS_CC)) {
861-
retval = 1;
862-
} else {
841+
if (only_subclass && instance_ce == *ce) {
863842
retval = 0;
843+
} else {
844+
retval = instanceof_function(instance_ce, *ce TSRMLS_CC);
864845
}
865846
}
866847

ext/standard/tests/class_object/is_a_variation_001.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,23 @@ Arg value
144144
bool(false)
145145

146146
Arg value
147+
148+
Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
147149
bool(false)
148150

149151
Arg value
152+
153+
Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
150154
bool(false)
151155

152156
Arg value string
157+
158+
Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
153159
bool(false)
154160

155161
Arg value String
162+
163+
Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
156164
bool(false)
157165

158166
Arg value

0 commit comments

Comments
 (0)