com php-src: Preserve trait method alias name during preloading: ext/opcache/ZendAccelerator.c ext/opcache/tests/preload.inc
ext/opcache/tests/preload_trait_alias.phpt

From: Date: Tue, 03 Nov 2020 09:55:59 +0000
Subject: com php-src: Preserve trait method alias name during preloading: ext/opcache/ZendAccelerator.c ext/opcache/tests/preload.inc
ext/opcache/tests/preload_trait_alias.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-114043@lists.php.net to get a copy of this message
Commit: 6f2431860b309df87d8a4d977b0a0bfb05182855 Author: Nikita Popov <nikita.ppv@gmail.com> Tue, 3 Nov 2020 10:55:59 +0100 Parents: 53c417d81c04d76d873a217f32cbd204c49513f6 Branches: PHP-8.0 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6f2431860b309df87d8a4d977b0a0bfb05182855 Log: Preserve trait method alias name during preloading Changed paths: M ext/opcache/ZendAccelerator.c M ext/opcache/tests/preload.inc A ext/opcache/tests/preload_trait_alias.phpt Diff: diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 22b484b7894..39d04f9a958 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -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; diff --git a/ext/opcache/tests/preload.inc b/ext/opcache/tests/preload.inc index 52bb60e3484..0ef3b4f56e3 100644 --- a/ext/opcache/tests/preload.inc +++ b/ext/opcache/tests/preload.inc @@ -45,6 +45,12 @@ class Z { class Z2 extends Z {} +class TraitAliasTest { + use T1 { + T1::foo as bar; + } +} + function get_anon() { return new class {}; } diff --git a/ext/opcache/tests/preload_trait_alias.phpt b/ext/opcache/tests/preload_trait_alias.phpt new file mode 100644 index 00000000000..89b843cd76e --- /dev/null +++ b/ext/opcache/tests/preload_trait_alias.phpt @@ -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" +}

« previous php.cvs (#114043) next »