dmitry Mon, 04 Jul 2011 14:55:39 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=312904
Log:
Fixed bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
Bug: https://bugs.php.net/53727 (Assigned) Inconsistent behavior of
is_subclass_of with interfaces
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
A php/php-src/branches/PHP_5_3/Zend/tests/bug53727.phpt
U php/php-src/branches/PHP_5_3/Zend/tests/is_a.phpt
U php/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c
U
php/php-src/branches/PHP_5_3/ext/standard/tests/class_object/is_a_variation_001.phpt
A php/php-src/branches/PHP_5_4/Zend/tests/bug53727.phpt
U php/php-src/branches/PHP_5_4/Zend/tests/is_a.phpt
U php/php-src/branches/PHP_5_4/Zend/zend_builtin_functions.c
U
php/php-src/branches/PHP_5_4/ext/standard/tests/class_object/is_a_variation_001.phpt
A php/php-src/trunk/Zend/tests/bug53727.phpt
U php/php-src/trunk/Zend/tests/is_a.phpt
U php/php-src/trunk/Zend/zend_builtin_functions.c
U
php/php-src/trunk/ext/standard/tests/class_object/is_a_variation_001.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/branches/PHP_5_3/NEWS 2011-07-04 14:55:39 UTC (rev 312904)
@@ -1,6 +1,10 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2011, PHP 5.3.7
+- Core
+ . Fixed bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
+ (Ralph Schindler, Dmitry)
+
- PDO DBlib:
. Fixed bug #54329 (MSSql extension memory leak).
(dotslashpok at gmail dot com)
Added: php/php-src/branches/PHP_5_3/Zend/tests/bug53727.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/tests/bug53727.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/Zend/tests/bug53727.phpt 2011-07-04 14:55:39 UTC (rev 312904)
@@ -0,0 +1,22 @@
+--TEST--
+Bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
+--FILE--
+<?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";
+--EXPECT--
+true
+true
+true
+true
Modified: php/php-src/branches/PHP_5_3/Zend/tests/is_a.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/tests/is_a.phpt 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/branches/PHP_5_3/Zend/tests/is_a.phpt 2011-07-04 14:55:39 UTC (rev 312904)
@@ -38,6 +38,6 @@
bool(false)
bool(false)
bool(true)
-bool(false)
+bool(true)
AUTOLOAD 'X1'
bool(false)
Modified: php/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c 2011-07-04 14:55:39 UTC (rev 312904)
@@ -822,46 +822,27 @@
return;
}
- if (only_subclass && Z_TYPE_P(obj) == IS_STRING) {
+ if (Z_TYPE_P(obj) == IS_STRING) {
zend_class_entry **the_ce;
if (zend_lookup_class(Z_STRVAL_P(obj), Z_STRLEN_P(obj), &the_ce TSRMLS_CC) == FAILURE) {
zend_error(E_WARNING, "Unknown class passed as parameter");
RETURN_FALSE;
}
instance_ce = *the_ce;
- } else if (Z_TYPE_P(obj) != IS_OBJECT) {
- RETURN_FALSE;
+ } else if (Z_TYPE_P(obj) == IS_OBJECT && HAS_CLASS_ENTRY(*obj)) {
+ instance_ce = Z_OBJCE_P(obj);
} else {
- instance_ce = NULL;
- }
-
- /* TBI!! new object handlers */
- if (Z_TYPE_P(obj) == IS_OBJECT && !HAS_CLASS_ENTRY(*obj)) {
RETURN_FALSE;
}
if (zend_lookup_class_ex(class_name, class_name_len, 0, &ce TSRMLS_CC) == FAILURE) {
retval = 0;
} else {
- if (only_subclass) {
- if (!instance_ce) {
- instance_ce = Z_OBJCE_P(obj)->parent;
- } else {
- instance_ce = instance_ce->parent;
- }
+ if (only_subclass && instance_ce == *ce) {
+ retval = 0;
} else {
- instance_ce = Z_OBJCE_P(obj);
+ retval = instanceof_function(instance_ce, *ce TSRMLS_CC);
}
-
- if (!instance_ce) {
- RETURN_FALSE;
- }
-
- if (instanceof_function(instance_ce, *ce TSRMLS_CC)) {
- retval = 1;
- } else {
- retval = 0;
- }
}
RETURN_BOOL(retval);
Modified: php/php-src/branches/PHP_5_3/ext/standard/tests/class_object/is_a_variation_001.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/tests/class_object/is_a_variation_001.phpt 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/branches/PHP_5_3/ext/standard/tests/class_object/is_a_variation_001.phpt 2011-07-04 14:55:39 UTC (rev 312904)
@@ -144,15 +144,23 @@
bool(false)
Arg value
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value string
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value String
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value
Added: php/php-src/branches/PHP_5_4/Zend/tests/bug53727.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/tests/bug53727.phpt (rev 0)
+++ php/php-src/branches/PHP_5_4/Zend/tests/bug53727.phpt 2011-07-04 14:55:39 UTC (rev 312904)
@@ -0,0 +1,22 @@
+--TEST--
+Bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
+--FILE--
+<?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";
+--EXPECT--
+true
+true
+true
+true
Modified: php/php-src/branches/PHP_5_4/Zend/tests/is_a.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/tests/is_a.phpt 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/branches/PHP_5_4/Zend/tests/is_a.phpt 2011-07-04 14:55:39 UTC (rev 312904)
@@ -38,6 +38,6 @@
bool(false)
bool(false)
bool(true)
-bool(false)
+bool(true)
AUTOLOAD 'X1'
bool(false)
Modified: php/php-src/branches/PHP_5_4/Zend/zend_builtin_functions.c
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/zend_builtin_functions.c 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/branches/PHP_5_4/Zend/zend_builtin_functions.c 2011-07-04 14:55:39 UTC (rev 312904)
@@ -845,45 +845,26 @@
return;
}
- if (only_subclass && Z_TYPE_P(obj) == IS_STRING) {
+ if (Z_TYPE_P(obj) == IS_STRING) {
zend_class_entry **the_ce;
if (zend_lookup_class(Z_STRVAL_P(obj), Z_STRLEN_P(obj), &the_ce TSRMLS_CC) == FAILURE) {
zend_error(E_WARNING, "Unknown class passed as parameter");
RETURN_FALSE;
}
instance_ce = *the_ce;
- } else if (Z_TYPE_P(obj) != IS_OBJECT) {
- RETURN_FALSE;
+ } else if (Z_TYPE_P(obj) == IS_OBJECT && HAS_CLASS_ENTRY(*obj)) {
+ instance_ce = Z_OBJCE_P(obj);
} else {
- instance_ce = NULL;
- }
-
- /* TBI!! new object handlers */
- if (Z_TYPE_P(obj) == IS_OBJECT && !HAS_CLASS_ENTRY(*obj)) {
RETURN_FALSE;
}
if (zend_lookup_class_ex(class_name, class_name_len, NULL, 0, &ce TSRMLS_CC) == FAILURE) {
retval = 0;
} else {
- if (only_subclass) {
- if (!instance_ce) {
- instance_ce = Z_OBJCE_P(obj)->parent;
- } else {
- instance_ce = instance_ce->parent;
- }
- } else {
- instance_ce = Z_OBJCE_P(obj);
- }
-
- if (!instance_ce) {
- RETURN_FALSE;
- }
-
- if (instanceof_function(instance_ce, *ce TSRMLS_CC)) {
- retval = 1;
- } else {
+ if (only_subclass && instance_ce == *ce) {
retval = 0;
+ } else {
+ retval = instanceof_function(instance_ce, *ce TSRMLS_CC);
}
}
Modified: php/php-src/branches/PHP_5_4/ext/standard/tests/class_object/is_a_variation_001.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/ext/standard/tests/class_object/is_a_variation_001.phpt 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/branches/PHP_5_4/ext/standard/tests/class_object/is_a_variation_001.phpt 2011-07-04 14:55:39 UTC (rev 312904)
@@ -144,15 +144,23 @@
bool(false)
Arg value
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value string
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value String
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value
Added: php/php-src/trunk/Zend/tests/bug53727.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/bug53727.phpt (rev 0)
+++ php/php-src/trunk/Zend/tests/bug53727.phpt 2011-07-04 14:55:39 UTC (rev 312904)
@@ -0,0 +1,22 @@
+--TEST--
+Bug #53727 (Inconsistent behavior of is_subclass_of with interfaces)
+--FILE--
+<?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";
+--EXPECT--
+true
+true
+true
+true
Modified: php/php-src/trunk/Zend/tests/is_a.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/is_a.phpt 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/trunk/Zend/tests/is_a.phpt 2011-07-04 14:55:39 UTC (rev 312904)
@@ -38,6 +38,6 @@
bool(false)
bool(false)
bool(true)
-bool(false)
+bool(true)
AUTOLOAD 'X1'
bool(false)
Modified: php/php-src/trunk/Zend/zend_builtin_functions.c
===================================================================
--- php/php-src/trunk/Zend/zend_builtin_functions.c 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/trunk/Zend/zend_builtin_functions.c 2011-07-04 14:55:39 UTC (rev 312904)
@@ -845,45 +845,26 @@
return;
}
- if (only_subclass && Z_TYPE_P(obj) == IS_STRING) {
+ if (Z_TYPE_P(obj) == IS_STRING) {
zend_class_entry **the_ce;
if (zend_lookup_class(Z_STRVAL_P(obj), Z_STRLEN_P(obj), &the_ce TSRMLS_CC) == FAILURE) {
zend_error(E_WARNING, "Unknown class passed as parameter");
RETURN_FALSE;
}
instance_ce = *the_ce;
- } else if (Z_TYPE_P(obj) != IS_OBJECT) {
- RETURN_FALSE;
+ } else if (Z_TYPE_P(obj) == IS_OBJECT && HAS_CLASS_ENTRY(*obj)) {
+ instance_ce = Z_OBJCE_P(obj);
} else {
- instance_ce = NULL;
- }
-
- /* TBI!! new object handlers */
- if (Z_TYPE_P(obj) == IS_OBJECT && !HAS_CLASS_ENTRY(*obj)) {
RETURN_FALSE;
}
if (zend_lookup_class_ex(class_name, class_name_len, NULL, 0, &ce TSRMLS_CC) == FAILURE) {
retval = 0;
} else {
- if (only_subclass) {
- if (!instance_ce) {
- instance_ce = Z_OBJCE_P(obj)->parent;
- } else {
- instance_ce = instance_ce->parent;
- }
- } else {
- instance_ce = Z_OBJCE_P(obj);
- }
-
- if (!instance_ce) {
- RETURN_FALSE;
- }
-
- if (instanceof_function(instance_ce, *ce TSRMLS_CC)) {
- retval = 1;
- } else {
+ if (only_subclass && instance_ce == *ce) {
retval = 0;
+ } else {
+ retval = instanceof_function(instance_ce, *ce TSRMLS_CC);
}
}
Modified: php/php-src/trunk/ext/standard/tests/class_object/is_a_variation_001.phpt
===================================================================
--- php/php-src/trunk/ext/standard/tests/class_object/is_a_variation_001.phpt 2011-07-04 12:49:46 UTC (rev 312903)
+++ php/php-src/trunk/ext/standard/tests/class_object/is_a_variation_001.phpt 2011-07-04 14:55:39 UTC (rev 312904)
@@ -144,15 +144,23 @@
bool(false)
Arg value
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value string
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value String
+
+Warning: Unknown class passed as parameter in %sis_a_variation_001.php on line %d
bool(false)
Arg value
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php