summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Marr <gron@php.net>2011-07-23 13:48:07 +0000
committerStefan Marr <gron@php.net>2011-07-23 13:48:07 +0000
commitf295302af66efd30a6a8ca72be7872a4696ce5b9 (patch)
tree95ecfc38adfba1498501f44375ce803ae83ef6bf
parentc724b2eeb1c1192faab05cad70b370c262dd9c5a (diff)
downloadphp-git-f295302af66efd30a6a8ca72be7872a4696ce5b9.tar.gz
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.
-rw-r--r--Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt23
-rw-r--r--Zend/zend_compile.c14
2 files changed, 31 insertions, 6 deletions
diff --git a/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt b/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt
new file mode 100644
index 0000000000..1b9d98dac0
--- /dev/null
+++ b/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt
@@ -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
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 06bdf36fea..0069f3f44e 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3919,13 +3919,15 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {
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 */