com php-src: Fix #76700 - Methods with altered visibility need to be added again: Zend/tests/traits/bug76700.phpt Zend/zend_inheritance .c
| From: | Xinchen Hui | Date: | Tue, 07 Aug 2018 06:22:37 +0000 |
| Subject: | com php-src: Fix #76700 - Methods with altered visibility need to be added again: Zend/tests/traits/bug76700.phpt Zend/zend_inheritance .c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-102849@lists.php.net to get a copy of this message | ||
Commit: 887235773d1848108f842184c978ba37875768f2
Author: Pedro Magalhães <mail@pmmaga.net> Fri, 3 Aug 2018 17:30:03 +0100
Committer: Xinchen Hui <laruence@gmail.com> Tue, 7 Aug 2018 14:22:37 +0800
Parents: 2b1d79ce6661efdfae881884ca40b4ca7fc991e7
Branches: PHP-7.3 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=887235773d1848108f842184c978ba37875768f2
Log:
Fix #76700 - Methods with altered visibility need to be added again
Bugs:
https://bugs.php.net/76700
Changed paths:
A Zend/tests/traits/bug76700.phpt
M Zend/zend_inheritance.c
Diff:
diff --git a/Zend/tests/traits/bug76700.phpt b/Zend/tests/traits/bug76700.phpt
new file mode 100644
index 0000000..5b746d5
--- /dev/null
+++ b/Zend/tests/traits/bug76700.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Bug #76700 (false-positive "Error: Call to protected method" when using trait aliases)
+--FILE--
+<?php
+trait T1
+{
+ protected function aa() { echo 123; }
+}
+
+trait T2
+{
+ use T1 {
+ aa as public;
+ }
+}
+
+class A
+{
+ use T1;
+}
+
+class B extends A
+{
+ use T2;
+}
+
+$b = new B();
+$b->aa();
+
+--EXPECT--
+123
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index dc55410...8af409f 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -1178,8 +1178,10 @@ 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 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) {
+ /* 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 (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)) {
return;
}