Skip to content

Commit

Permalink
Preserve trait method alias name during preloading
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Nov 3, 2020
1 parent 53c417d commit 6f24318
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -4147,11 +4147,13 @@ static void preload_fix_trait_methods(zend_class_entry *ce)
if (op_array->fn_flags & ZEND_ACC_TRAIT_CLONE) {
zend_op_array *orig_op_array = zend_shared_alloc_get_xlat_entry(op_array->opcodes);
if (orig_op_array) {
zend_string *function_name = op_array->function_name;
zend_class_entry *scope = op_array->scope;
uint32_t fn_flags = op_array->fn_flags;
zend_function *prototype = op_array->prototype;
HashTable *ht = op_array->static_variables;
*op_array = *orig_op_array;
op_array->function_name = function_name;
op_array->scope = scope;
op_array->fn_flags = fn_flags;
op_array->prototype = prototype;
Expand Down
6 changes: 6 additions & 0 deletions ext/opcache/tests/preload.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class Z {

class Z2 extends Z {}

class TraitAliasTest {
use T1 {
T1::foo as bar;
}
}

function get_anon() {
return new class {};
}
Expand Down
23 changes: 23 additions & 0 deletions ext/opcache/tests/preload_trait_alias.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Preloading trait uses with aliased names
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload={PWD}/preload.inc
--SKIPIF--
<?php
require_once('skipif.inc');
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php
var_dump(get_class_methods('TraitAliasTest'));
?>
--EXPECT--
array(2) {
[0]=>
string(3) "bar"
[1]=>
string(3) "foo"
}

0 comments on commit 6f24318

Please sign in to comment.