Skip to content

Fix persisting of inherited class constants #14114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ext/opcache/zend_persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,17 @@ static zend_property_info *zend_persist_property_info(zend_property_info *prop)

static void zend_persist_class_constant(zval *zv)
{
zend_class_constant *c = zend_shared_alloc_get_xlat_entry(Z_PTR_P(zv));
zend_class_constant *orig_c = Z_PTR_P(zv);
zend_class_constant *c = zend_shared_alloc_get_xlat_entry(orig_c);
zend_class_entry *ce;

if (c) {
Z_PTR_P(zv) = c;
return;
} else if (((orig_c->ce->ce_flags & ZEND_ACC_IMMUTABLE) && !(Z_CONSTANT_FLAGS(orig_c->value) & CONST_OWNED))
|| orig_c->ce->type == ZEND_INTERNAL_CLASS) {
/* Class constant comes from a different file in shm or internal class, keep existing pointer. */
return;
} else if (!ZCG(current_persistent_script)->corrupted
&& zend_accel_in_shm(Z_PTR_P(zv))) {
return;
Expand Down
6 changes: 6 additions & 0 deletions ext/opcache/zend_persist_calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "zend_shared_alloc.h"
#include "zend_operators.h"
#include "zend_attributes.h"
#include "zend_constants.h"

#define ADD_DUP_SIZE(m,s) ZCG(current_persistent_script)->size += zend_shared_memdup_size((void*)m, s)
#define ADD_SIZE(m) ZCG(current_persistent_script)->size += ZEND_ALIGNED_SIZE(m)
Expand Down Expand Up @@ -386,6 +387,11 @@ static void zend_persist_class_constant_calc(zval *zv)
zend_class_constant *c = Z_PTR_P(zv);

if (!zend_shared_alloc_get_xlat_entry(c)) {
if (((c->ce->ce_flags & ZEND_ACC_IMMUTABLE) && !(Z_CONSTANT_FLAGS(c->value) & CONST_OWNED))
|| c->ce->type == ZEND_INTERNAL_CLASS) {
/* Class constant comes from a different file in shm or internal class, keep existing pointer. */
return;
}
if (!ZCG(current_persistent_script)->corrupted
&& zend_accel_in_shm(Z_PTR_P(zv))) {
return;
Expand Down
16 changes: 16 additions & 0 deletions ext/zend_test/tests/gh14109.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
GH-14109: User class extending internal class with attributes
--EXTENSIONS--
zend_test
--FILE--
<?php
class Test extends ZendAttributeTest {}
foreach ((new ReflectionClassConstant(Test::class, 'TEST_CONST'))->getAttributes() as $attribute) {
var_dump($attribute->newInstance());
}
?>
--EXPECTF--
object(ZendTestRepeatableAttribute)#%d (0) {
}
object(ZendTestRepeatableAttribute)#%d (0) {
}
Loading