Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix GH-18534: FPM exit code 70 with enabled opcache and hooked properties in traits
This commit is contained in:
Niels Dossche 2025-05-19 19:22:16 +02:00
commit 383aad8007
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
5 changed files with 91 additions and 17 deletions

View file

@ -1556,7 +1556,7 @@ void zend_foreach_op_array(zend_script *script, zend_op_array_func_t func, void
if (property->ce == ce && property->hooks) { if (property->ce == ce && property->hooks) {
for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) { for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
zend_function *hook = hooks[i]; zend_function *hook = hooks[i];
if (hook && hook->common.scope == ce) { if (hook && hook->common.scope == ce && !(hooks[i]->op_array.fn_flags & ZEND_ACC_TRAIT_CLONE)) {
zend_foreach_op_array_helper(&hooks[i]->op_array, func, context); zend_foreach_op_array_helper(&hooks[i]->op_array, func, context);
} }
} }

View file

@ -2983,6 +2983,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
hooks[j] = new_fn; hooks[j] = new_fn;
} }
} }
ce->num_hooked_props++;
} }
} ZEND_HASH_FOREACH_END(); } ZEND_HASH_FOREACH_END();
} }

View file

@ -4298,20 +4298,38 @@ static void preload_remove_empty_includes(void)
static void preload_register_trait_methods(zend_class_entry *ce) { static void preload_register_trait_methods(zend_class_entry *ce) {
zend_op_array *op_array; zend_op_array *op_array;
zend_property_info *info;
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) {
if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) { if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
ZEND_ASSERT(op_array->refcount && "Must have refcount pointer"); ZEND_ASSERT(op_array->refcount && "Must have refcount pointer");
zend_shared_alloc_register_xlat_entry(op_array->refcount, op_array); zend_shared_alloc_register_xlat_entry(op_array->refcount, op_array);
} }
} ZEND_HASH_FOREACH_END(); } ZEND_HASH_FOREACH_END();
if (ce->num_hooked_props > 0) {
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, info) {
if (info->hooks) {
for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
if (info->hooks[i]) {
op_array = &info->hooks[i]->op_array;
if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
ZEND_ASSERT(op_array->refcount && "Must have refcount pointer");
zend_shared_alloc_register_xlat_entry(op_array->refcount, op_array);
}
}
}
}
} ZEND_HASH_FOREACH_END();
}
} }
static void preload_fix_trait_methods(zend_class_entry *ce) static void preload_fix_trait_op_array(zend_op_array *op_array)
{ {
zend_op_array *op_array; if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
return;
}
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) {
if (op_array->fn_flags & ZEND_ACC_TRAIT_CLONE) {
zend_op_array *orig_op_array = zend_shared_alloc_get_xlat_entry(op_array->refcount); zend_op_array *orig_op_array = zend_shared_alloc_get_xlat_entry(op_array->refcount);
ZEND_ASSERT(orig_op_array && "Must be in xlat table"); ZEND_ASSERT(orig_op_array && "Must be in xlat table");
@ -4327,7 +4345,28 @@ static void preload_fix_trait_methods(zend_class_entry *ce)
op_array->prototype = prototype; op_array->prototype = prototype;
op_array->static_variables = ht; op_array->static_variables = ht;
} }
static void preload_fix_trait_methods(zend_class_entry *ce)
{
zend_op_array *op_array;
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) {
preload_fix_trait_op_array(op_array);
} ZEND_HASH_FOREACH_END(); } ZEND_HASH_FOREACH_END();
if (ce->num_hooked_props > 0) {
zend_property_info *info;
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, info) {
if (info->hooks) {
for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
if (info->hooks[i]) {
op_array = &info->hooks[i]->op_array;
preload_fix_trait_op_array(op_array);
}
}
}
} ZEND_HASH_FOREACH_END();
}
} }
static void preload_optimize(zend_persistent_script *script) static void preload_optimize(zend_persistent_script *script)

View file

@ -0,0 +1,21 @@
--TEST--
GH-18534 (FPM exit code 70 with enabled opcache and hooked properties in traits)
--EXTENSIONS--
opcache
--SKIPIF--
<?php if (PHP_OS_FAMILY === 'Windows') die('skip preloading does not work on Windows'); ?>
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.preload={PWD}/gh18534_preload.inc
--FILE--
<?php
require_once __DIR__ . '/gh18534_preload.inc';
$test = new DummyModel;
var_dump($test->dummyProperty2);
?>
--EXPECT--
NULL

View file

@ -0,0 +1,13 @@
<?php
trait DummyTrait
{
public ?string $dummyProperty2 {
get => null;
}
}
class DummyModel
{
use DummyTrait;
}