gron Sat, 23 Jul 2011 13:48:07 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=313632
Log: Fixed bug in the handling of conflicting property initializers for traits. # Bug was uncovered by discussion in http://news.php.net/php.internals/54129 # Forgot to check the actual value of the initializer comparison, only checked # whether comparison was successful which is not enough. Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt =================================================================== --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt 2011-07-23 13:48:07 UTC (rev 313632) @@ -0,0 +1,23 @@ +--TEST-- +Properties are considered incompatible if they are different in any of their +defined characteristics. Thus, initialization values have to be equal, too. +--FILE-- +<?php +error_reporting(E_ALL); + +trait foo +{ + public $zoo = 'foo::zoo'; +} + +class baz +{ + use foo; + public $zoo = 'baz::zoo'; +} + +$obj = new baz(); +echo $obj->zoo, "\n"; +?> +--EXPECTF-- +Fatal error: baz and foo define the same property ($zoo) in the composition of baz. However, the definition differs and is considered incompatible. Class was composed in %s on line %d \ No newline at end of file Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c =================================================================== --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-07-23 13:48:02 UTC (rev 313631) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-07-23 13:48:07 UTC (rev 313632) @@ -3919,13 +3919,15 @@ if ((coliding_prop->flags & ZEND_ACC_PPP_MASK) == (property_info->flags & ZEND_ACC_PPP_MASK)) { /* flags are identical, now the value needs to be checked */ if (property_info->flags & ZEND_ACC_STATIC) { - not_compatible = compare_function(&compare_result, - ce->default_static_members_table[coliding_prop->offset], - ce->traits[i]->default_static_members_table[property_info->offset] TSRMLS_CC) == FAILURE; + not_compatible = (FAILURE == compare_function(&compare_result, + ce->default_static_members_table[coliding_prop->offset], + ce->traits[i]->default_static_members_table[property_info->offset] TSRMLS_CC)) + || (Z_LVAL(compare_result) != 0); } else { - not_compatible = compare_function(&compare_result, - ce->default_properties_table[coliding_prop->offset], - ce->traits[i]->default_properties_table[property_info->offset] TSRMLS_CC) == FAILURE; + not_compatible = (FAILURE == compare_function(&compare_result, + ce->default_properties_table[coliding_prop->offset], + ce->traits[i]->default_properties_table[property_info->offset] TSRMLS_CC)) + || (Z_LVAL(compare_result) != 0); } } else { /* the flags are not identical, thus, we assume properties are not compatible */ Added: php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt =================================================================== --- php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt 2011-07-23 13:48:07 UTC (rev 313632) @@ -0,0 +1,23 @@ +--TEST-- +Properties are considered incompatible if they are different in any of their +defined characteristics. Thus, initialization values have to be equal, too. +--FILE-- +<?php +error_reporting(E_ALL); + +trait foo +{ + public $zoo = 'foo::zoo'; +} + +class baz +{ + use foo; + public $zoo = 'baz::zoo'; +} + +$obj = new baz(); +echo $obj->zoo, "\n"; +?> +--EXPECTF-- +Fatal error: baz and foo define the same property ($zoo) in the composition of baz. However, the definition differs and is considered incompatible. Class was composed in %s on line %d \ No newline at end of file Modified: php/php-src/trunk/Zend/zend_compile.c =================================================================== --- php/php-src/trunk/Zend/zend_compile.c 2011-07-23 13:48:02 UTC (rev 313631) +++ php/php-src/trunk/Zend/zend_compile.c 2011-07-23 13:48:07 UTC (rev 313632) @@ -3919,13 +3919,15 @@ if ((coliding_prop->flags & ZEND_ACC_PPP_MASK) == (property_info->flags & ZEND_ACC_PPP_MASK)) { /* flags are identical, now the value needs to be checked */ if (property_info->flags & ZEND_ACC_STATIC) { - not_compatible = compare_function(&compare_result, - ce->default_static_members_table[coliding_prop->offset], - ce->traits[i]->default_static_members_table[property_info->offset] TSRMLS_CC) == FAILURE; + not_compatible = (FAILURE == compare_function(&compare_result, + ce->default_static_members_table[coliding_prop->offset], + ce->traits[i]->default_static_members_table[property_info->offset] TSRMLS_CC)) + || (Z_LVAL(compare_result) != 0); } else { - not_compatible = compare_function(&compare_result, - ce->default_properties_table[coliding_prop->offset], - ce->traits[i]->default_properties_table[property_info->offset] TSRMLS_CC) == FAILURE; + not_compatible = (FAILURE == compare_function(&compare_result, + ce->default_properties_table[coliding_prop->offset], + ce->traits[i]->default_properties_table[property_info->offset] TSRMLS_CC)) + || (Z_LVAL(compare_result) != 0); } } else { /* the flags are not identical, thus, we assume properties are not compatible */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php