summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2018-08-22 14:08:46 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2018-08-22 14:08:46 +0200
commit1f698e0f94604ed4be5a1ed0fc91831ce06bae52 (patch)
treef45e0b2585a05841a1aade4e162a1feca16ba84e
parentd1ff6c3a4e3536371d3b45eb56b916c68e10197f (diff)
parent9ace33b9c5d06b869b2aec577b119b0494840931 (diff)
downloadphp-git-1f698e0f94604ed4be5a1ed0fc91831ce06bae52.tar.gz
Merge branch 'PHP-7.3'
* PHP-7.3: Fix #76773 - Methods with a concrete scope need to be added again
-rw-r--r--Zend/tests/traits/bug76773.phpt33
-rw-r--r--Zend/zend_inheritance.c7
2 files changed, 37 insertions, 3 deletions
diff --git a/Zend/tests/traits/bug76773.phpt b/Zend/tests/traits/bug76773.phpt
new file mode 100644
index 0000000000..2601d1cdda
--- /dev/null
+++ b/Zend/tests/traits/bug76773.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Bug #76773 (Traits used on the parent are ignored for child classes)
+--FILE--
+<?php
+
+trait MyTrait
+{
+ public function hello()
+ {
+ echo __CLASS__, "\n";
+
+ if (\is_callable(array('parent', __FUNCTION__))) {
+ parent::hello();
+ }
+ }
+}
+
+class ParentClass
+{
+ use MyTrait;
+}
+
+class ChildClass extends ParentClass
+{
+ use MyTrait;
+}
+
+$c = new ChildClass();
+$c->hello();
+
+--EXPECT--
+ChildClass
+ParentClass
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index 9df10b3a97..c5bc61d6c5 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -1178,10 +1178,11 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, zend_s
zend_function *new_fn;
if ((existing_fn = zend_hash_find_ptr(&ce->function_table, key)) != NULL) {
- /* if it is the same function with the same visibility regardless of where it is coming from */
- /* there is no conflict and we do not need to add it again */
+ /* if it is the same function with the same visibility and has not been assigned a class scope yet, regardless
+ * of where it is coming from there is no conflict and we do not need to add it again */
if (existing_fn->op_array.opcodes == fn->op_array.opcodes &&
- (existing_fn->common.fn_flags & ZEND_ACC_PPP_MASK) == (fn->common.fn_flags & ZEND_ACC_PPP_MASK)) {
+ (existing_fn->common.fn_flags & ZEND_ACC_PPP_MASK) == (fn->common.fn_flags & ZEND_ACC_PPP_MASK) &&
+ (existing_fn->common.scope->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) {
return;
}