File tree Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-14009: Traits inherit prototype
3
+ --FILE--
4
+ <?php
5
+
6
+ class P {
7
+ protected function common () {
8
+ throw new Exception ('Unreachable ' );
9
+ }
10
+ }
11
+
12
+ class A extends P {
13
+ public function test (P $ sibling ) {
14
+ $ sibling ->common ();
15
+ }
16
+ }
17
+
18
+ class B extends P {
19
+ protected function common () {
20
+ echo __METHOD__ , "\n" ;
21
+ }
22
+ }
23
+
24
+ trait T {
25
+ protected function common () {
26
+ echo __METHOD__ , "\n" ;
27
+ }
28
+ }
29
+
30
+ class C extends P {
31
+ use T;
32
+ }
33
+
34
+ $ a = new A ();
35
+ $ a ->test (new B ());
36
+ $ a ->test (new C ());
37
+
38
+ ?>
39
+ --EXPECT--
40
+ B::common
41
+ T::common
Original file line number Diff line number Diff line change @@ -1146,20 +1146,24 @@ static zend_always_inline inheritance_status do_inheritance_check_on_method_ex(
1146
1146
parent = proto ;
1147
1147
}
1148
1148
1149
- if (!check_only && child -> common .prototype != proto && child_zv ) {
1149
+ if (!check_only && child -> common .prototype != proto ) {
1150
1150
do {
1151
+ bool copied = false;
1151
1152
if (child -> common .scope != ce && child -> type == ZEND_USER_FUNCTION ) {
1152
1153
if (ce -> ce_flags & ZEND_ACC_INTERFACE ) {
1153
1154
/* Few parent interfaces contain the same method */
1154
1155
break ;
1155
- } else {
1156
+ } else if ( child_zv ) {
1156
1157
/* op_array wasn't duplicated yet */
1157
1158
zend_function * new_function = zend_arena_alloc (& CG (arena ), sizeof (zend_op_array ));
1158
1159
memcpy (new_function , child , sizeof (zend_op_array ));
1159
1160
Z_PTR_P (child_zv ) = child = new_function ;
1161
+ copied = true;
1160
1162
}
1161
1163
}
1162
- child -> common .prototype = proto ;
1164
+ if (copied || child_scope == ce ) {
1165
+ child -> common .prototype = proto ;
1166
+ }
1163
1167
} while (0 );
1164
1168
}
1165
1169
You can’t perform that action at this time.
0 commit comments