Skip to content

Commit 6f24318

Browse files
committed
Preserve trait method alias name during preloading
1 parent 53c417d commit 6f24318

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,11 +4147,13 @@ static void preload_fix_trait_methods(zend_class_entry *ce)
41474147
if (op_array->fn_flags & ZEND_ACC_TRAIT_CLONE) {
41484148
zend_op_array *orig_op_array = zend_shared_alloc_get_xlat_entry(op_array->opcodes);
41494149
if (orig_op_array) {
4150+
zend_string *function_name = op_array->function_name;
41504151
zend_class_entry *scope = op_array->scope;
41514152
uint32_t fn_flags = op_array->fn_flags;
41524153
zend_function *prototype = op_array->prototype;
41534154
HashTable *ht = op_array->static_variables;
41544155
*op_array = *orig_op_array;
4156+
op_array->function_name = function_name;
41554157
op_array->scope = scope;
41564158
op_array->fn_flags = fn_flags;
41574159
op_array->prototype = prototype;

ext/opcache/tests/preload.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class Z {
4545

4646
class Z2 extends Z {}
4747

48+
class TraitAliasTest {
49+
use T1 {
50+
T1::foo as bar;
51+
}
52+
}
53+
4854
function get_anon() {
4955
return new class {};
5056
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Preloading trait uses with aliased names
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/preload.inc
8+
--SKIPIF--
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
13+
--FILE--
14+
<?php
15+
var_dump(get_class_methods('TraitAliasTest'));
16+
?>
17+
--EXPECT--
18+
array(2) {
19+
[0]=>
20+
string(3) "bar"
21+
[1]=>
22+
string(3) "foo"
23+
}

0 commit comments

Comments
 (0)