Commit 9153ad03577 for php

commit 9153ad03577feec8ff0255e4e1c7f22be50b723b
Author: Nora Dossche <7771979+ndossche@users.noreply.github.com>
Date:   Sun Nov 22 15:59:34 2026 +0100

    Rework how attributed constants are stored and handled (#24392)

    The original PR GH-16952 introduced special handling and a special flag
    to store the attribute via an OP_DATA opcode. It required special
    handling in various places.
    This commit reworks that by introducing a type specialization of the
    zend_constant structure and storing the attribute data in the main op
    array.
    This reduces complexity and removes special handling in various places.

diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS
index b75e3909f41..7349f29a6a7 100644
--- a/UPGRADING.INTERNALS
+++ b/UPGRADING.INTERNALS
@@ -31,6 +31,11 @@ PHP 8.7 INTERNALS UPGRADE NOTES
     allowed anymore. User-facing HashTables must have pDestructor = ZVAL_PTR_DTOR
     or NULL, and must be freed with zend_array_destroy(). Other HashTables can
     be freed with zend_hash_destroy() + pefree().
+  . Removed ZEND_ACC_PTR_OPS. Attributes of user constants are now stored in
+    the attributes table of the declaring file's main op_array.
+    zend_constant.attributes can therefore be shared.
+    Use zend_constant_attributes_offset() to get the offset of a constant's own attributes.
+    Added zend_get_attribute_str_ex() to look up an attribute at a raw offset.

 - Removed:
   . The ZEND_LOG_XOR() macro was removed.
@@ -131,6 +136,9 @@ PHP 8.7 INTERNALS UPGRADE NOTES
 4. OpCode changes
 ========================

+- ZEND_DECLARE_ATTRIBUTED_CONST no longer has an OP_DATA opline.
+  The offset of the constant's attributes in the op_array's attributes table is stored in extended_value.
+
 ========================
 5. SAPI changes
 ========================
diff --git a/Zend/zend_attributes.c b/Zend/zend_attributes.c
index c6615f13df9..3ed8739c3ed 100644
--- a/Zend/zend_attributes.c
+++ b/Zend/zend_attributes.c
@@ -310,6 +310,11 @@ ZEND_API zend_attribute *zend_get_attribute_str(const HashTable *attributes, con
 	return get_attribute_str(attributes, str, len, 0);
 }

+ZEND_API zend_attribute *zend_get_attribute_str_ex(const HashTable *attributes, const char *str, size_t len, uint32_t offset)
+{
+	return get_attribute_str(attributes, str, len, offset);
+}
+
 ZEND_API zend_attribute *zend_get_parameter_attribute(const HashTable *attributes, const zend_string *lcname, uint32_t offset)
 {
 	return get_attribute(attributes, lcname, offset + 1);
diff --git a/Zend/zend_attributes.h b/Zend/zend_attributes.h
index cc3d4e24add..d26923a0fcf 100644
--- a/Zend/zend_attributes.h
+++ b/Zend/zend_attributes.h
@@ -64,7 +64,16 @@ typedef struct _zend_attribute {
 	zend_string *validation_error;
 	uint32_t flags;
 	uint32_t lineno;
-	/* Parameter offsets start at 1, everything else uses 0. */
+	/* Identifies which declaration (e.g. function, parameter or constant) the attribute is attached to,
+	 * for tables that are shared by multiple declarations:
+	 * - Function attribute tables also hold the attributes of the parameters.
+	 *   Parameter #n uses offset n (one-based), the function itself uses 0.
+	 * - The attributes of all user constants declared in a file are stored in
+	 *   the attributes table of that file's main op_array.
+	 *   Each constant uses the index of its first attribute in that table as offset.
+	 *   For example, given `#[A] const X = 1; #[B, C] const Y = 2;`,
+	 *   A has offset 0 while B and C have offset 1.
+	 * Everything else uses 0. */
 	uint32_t offset;
 	uint32_t argc;
 	zend_attribute_arg args[1];
@@ -78,6 +87,8 @@ typedef struct _zend_internal_attribute {

 ZEND_API zend_attribute *zend_get_attribute(const HashTable *attributes, const zend_string *lcname);
 ZEND_API zend_attribute *zend_get_attribute_str(const HashTable *attributes, const char *str, size_t len);
+/* Raw offset, i.e. not adjusted for parameters. */
+ZEND_API zend_attribute *zend_get_attribute_str_ex(const HashTable *attributes, const char *str, size_t len, uint32_t offset);

 ZEND_API zend_attribute *zend_get_parameter_attribute(const HashTable *attributes, const zend_string *lcname, uint32_t offset);
 ZEND_API zend_attribute *zend_get_parameter_attribute_str(const HashTable *attributes, const char *str, size_t len, uint32_t offset);
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 42395006c3f..e8d462ed8ef 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -8315,23 +8315,12 @@ static void zend_compile_attributes(

 	if (*attributes != NULL) {
 		/* Allow delaying target validation for forward compatibility. */
-		const zend_attribute *delayed_target_validation = NULL;
-		if (target == ZEND_ATTRIBUTE_TARGET_PARAMETER) {
-			ZEND_ASSERT(offset >= 1);
-			/* zend_get_parameter_attribute_str will add 1 too */
-			delayed_target_validation = zend_get_parameter_attribute_str(
-				*attributes,
-				"delayedtargetvalidation",
-				strlen("delayedtargetvalidation"),
-				offset - 1
-			);
-		} else {
-			delayed_target_validation = zend_get_attribute_str(
-				*attributes,
-				"delayedtargetvalidation",
-				strlen("delayedtargetvalidation")
-			);
-		}
+		const zend_attribute *delayed_target_validation = zend_get_attribute_str_ex(
+			*attributes,
+			"delayedtargetvalidation",
+			strlen("delayedtargetvalidation"),
+			offset
+		);
 		/* Validate attributes in a secondary loop (needed to detect repeated attributes). */
 		ZEND_HASH_PACKED_FOREACH_PTR(*attributes, attr) {
 			if (attr->offset != offset || NULL == (config = zend_internal_attribute_get(attr->lcname))) {
@@ -10540,16 +10529,16 @@ static void zend_compile_const_decl(zend_ast *ast) /* {{{ */
 		);
 	}

-	HashTable *attributes = NULL;
-	zend_compile_attributes(&attributes, list->child[1], 0, ZEND_ATTRIBUTE_TARGET_CONST, 0);
+	/* Constants can only be declared at the top level, so the attributes of
+	 * all constants of a file are stored in the attributes table of the main op_array. */
+	HashTable **attributes = &CG(active_op_array)->attributes;
+	ZEND_ASSERT(!CG(active_op_array)->function_name);
+	uint32_t offset = *attributes ? zend_hash_num_elements(*attributes) : 0;
+	zend_compile_attributes(attributes, list->child[1], offset, ZEND_ATTRIBUTE_TARGET_CONST, 0);

 	ZEND_ASSERT(last_op != NULL);
 	last_op->opcode = ZEND_DECLARE_ATTRIBUTED_CONST;
-	znode attribs_node;
-	attribs_node.op_type = IS_CONST;
-	ZVAL_PTR(&attribs_node.u.constant, attributes);
-	zend_emit_op_data(&attribs_node);
-	CG(active_op_array)->fn_flags |= ZEND_ACC_PTR_OPS;
+	last_op->extended_value = offset;
 }
 /* }}}*/

diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h
index ec6d8b09bbe..e82d4212116 100644
--- a/Zend/zend_compile.h
+++ b/Zend/zend_compile.h
@@ -402,11 +402,6 @@ typedef struct _zend_oparray_context {
 /* supports opcache compile-time evaluation (funcs)       |     |     |     */
 #define ZEND_ACC_COMPILE_TIME_EVAL       (1 << 27) /*     |  X  |     |     */
 /*                                                        |     |     |     */
-/* Has IS_PTR operands that needs special cleaning; same  |     |     |     */
-/* value as ZEND_ACC_OVERRIDE but override is for class   |     |     |     */
-/* methods and this is for the top level op array         |     |     |     */
-#define ZEND_ACC_PTR_OPS                 (1 << 28) /*     |  X  |     |     */
-/*                                                        |     |     |     */
 /* has #[\NoDiscard] attribute                            |     |     |     */
 #define ZEND_ACC_NODISCARD               (1 << 29) /*     |  X  |     |     */
 /*                                                        |     |     |     */
diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c
index 736539f1a79..92221be70d1 100644
--- a/Zend/zend_constants.c
+++ b/Zend/zend_constants.c
@@ -75,6 +75,7 @@ static void copy_zend_constant(zval *zv)
 	zend_constant *c = Z_PTR_P(zv);

 	ZEND_ASSERT(ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
+	ZEND_ASSERT(!(ZEND_CONSTANT_FLAGS(c) & CONST_ATTRIBUTED));
 	Z_PTR_P(zv) = pemalloc(sizeof(zend_constant), 1);
 	memcpy(Z_PTR_P(zv), c, sizeof(zend_constant));

@@ -497,9 +498,10 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, const zend_class_entry *
 static void* zend_hash_add_constant(HashTable *ht, zend_string *key, const zend_constant *c)
 {
 	void *ret;
-	zend_constant *copy = pemalloc(sizeof(zend_constant), ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
+	size_t size = (ZEND_CONSTANT_FLAGS(c) & CONST_ATTRIBUTED) ? sizeof(zend_attributed_constant) : sizeof(zend_constant);
+	zend_constant *copy = pemalloc(size, ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);

-	memcpy(copy, c, sizeof(zend_constant));
+	memcpy(copy, c, size);
 	ret = zend_hash_add_ptr(ht, key, copy);
 	if (!ret) {
 		pefree(copy, ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
@@ -571,10 +573,11 @@ void zend_constant_add_attributes(zend_constant *c, HashTable *attributes) {
 	GC_TRY_ADDREF(attributes);
 	c->attributes = attributes;

-	zend_attribute *deprecated_attribute = zend_get_attribute_str(
+	zend_attribute *deprecated_attribute = zend_get_attribute_str_ex(
 		c->attributes,
 		"deprecated",
-		strlen("deprecated")
+		strlen("deprecated"),
+		zend_constant_attributes_offset(c)
 	);

 	if (deprecated_attribute) {
diff --git a/Zend/zend_constants.h b/Zend/zend_constants.h
index 9461ac764c9..493705fcb81 100644
--- a/Zend/zend_constants.h
+++ b/Zend/zend_constants.h
@@ -27,6 +27,7 @@
 #define CONST_DEPRECATED		(1<<2)				/* Deprecated */
 #define CONST_OWNED				(1<<3)				/* constant should be destroyed together with class */
 #define CONST_RECURSIVE			(1<<4)				/* Recursion protection for constant evaluation */
+#define CONST_ATTRIBUTED		(1<<5)				/* Allocated as zend_attributed_constant */

 #define CONST_IS_RECURSIVE(c) (Z_CONSTANT_FLAGS((c)->value) & CONST_RECURSIVE)
 #define CONST_PROTECT_RECURSION(c) \
@@ -44,6 +45,7 @@ typedef struct _zend_constant {
 	zval value;
 	zend_string *name;
 	zend_string *filename;
+	/* May be shared with other constants, see zend_attributed_constant. */
 	HashTable *attributes;
 } zend_constant;

@@ -58,6 +60,22 @@ typedef struct _zend_constant {
 			((_flags) & 0xff) | ((_module_number) << 8); \
 	} while (0)

+/* User constants declared with attributes.
+ * This is a type specialization of the zend_constant type. */
+typedef struct zend_attributed_constant {
+	zend_constant constant;
+	/* The zend_attribute.offset of this constant's attributes
+	 * in the attributes table of the main op_array of the declaring file. */
+	uint32_t attributes_offset;
+} zend_attributed_constant;
+
+static zend_always_inline uint32_t zend_constant_attributes_offset(const zend_constant *c)
+{
+	return (ZEND_CONSTANT_FLAGS(c) & CONST_ATTRIBUTED)
+		? ((const zend_attributed_constant *) c)->attributes_offset
+		: 0;
+}
+
 #define REGISTER_NULL_CONSTANT(name, flags)  zend_register_null_constant((name), sizeof(name)-1, (flags), module_number)
 #define REGISTER_BOOL_CONSTANT(name, bval, flags)  zend_register_bool_constant((name), sizeof(name)-1, (bval), (flags), module_number)
 #define REGISTER_LONG_CONSTANT(name, lval, flags)  zend_register_long_constant((name), sizeof(name)-1, (lval), (flags), module_number)
@@ -97,7 +115,7 @@ ZEND_API zend_constant *zend_register_double_constant(const char *name, size_t n
 ZEND_API zend_constant *zend_register_string_constant(const char *name, size_t name_len, const char *strval, int flags, int module_number);
 ZEND_API zend_constant *zend_register_stringl_constant(const char *name, size_t name_len, const char *strval, size_t strlen, int flags, int module_number);
 ZEND_API zend_constant *zend_register_constant(zend_constant *c);
-void zend_constant_add_attributes(zend_constant *c, HashTable *attributes);
+void ZEND_ATTRIBUTE_NONNULL zend_constant_add_attributes(zend_constant *c, HashTable *attributes);
 #ifdef ZTS
 void zend_copy_constants(HashTable *target, HashTable *source);
 #endif
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index b166bf7dc75..37f5e9eedca 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -1810,7 +1810,7 @@ ZEND_API zend_never_inline ZEND_COLD void zend_wrong_string_offset_error(void)
 	zend_throw_error(NULL, "%s", msg);
 }

-ZEND_COLD static zend_result ZEND_FASTCALL get_deprecation_suffix_from_attribute(HashTable *attributes, zend_class_entry* scope, zend_string **message_suffix)
+ZEND_COLD static zend_result ZEND_FASTCALL get_deprecation_suffix_from_attribute(HashTable *attributes, uint32_t offset, zend_class_entry* scope, zend_string **message_suffix)
 {
 	*message_suffix = ZSTR_EMPTY_ALLOC();

@@ -1818,7 +1818,7 @@ ZEND_COLD static zend_result ZEND_FASTCALL get_deprecation_suffix_from_attribute
 		return SUCCESS;
 	}

-	zend_attribute *deprecated = zend_get_attribute_str(attributes, "deprecated", sizeof("deprecated")-1);
+	zend_attribute *deprecated = zend_get_attribute_str_ex(attributes, "deprecated", sizeof("deprecated")-1, offset);

 	if (!deprecated) {
 		return SUCCESS;
@@ -1879,7 +1879,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_functi
 {
 	zend_string *message_suffix = ZSTR_EMPTY_ALLOC();

-	if (get_deprecation_suffix_from_attribute(fbc->common.attributes, fbc->common.scope, &message_suffix) == FAILURE) {
+	if (get_deprecation_suffix_from_attribute(fbc->common.attributes, 0, fbc->common.scope, &message_suffix) == FAILURE) {
 		return;
 	}

@@ -1986,7 +1986,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_class_constant(const zend_
 {
 	zend_string *message_suffix = ZSTR_EMPTY_ALLOC();

-	if (get_deprecation_suffix_from_attribute(c->attributes, c->ce, &message_suffix) == FAILURE) {
+	if (get_deprecation_suffix_from_attribute(c->attributes, 0, c->ce, &message_suffix) == FAILURE) {
 		return;
 	}

@@ -2007,7 +2007,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_constant(const zend_consta
 {
 	zend_string *message_suffix = ZSTR_EMPTY_ALLOC();

-	if (get_deprecation_suffix_from_attribute(c->attributes, NULL, &message_suffix) == FAILURE) {
+	if (get_deprecation_suffix_from_attribute(c->attributes, zend_constant_attributes_offset(c), NULL, &message_suffix) == FAILURE) {
 		return;
 	}

@@ -2027,7 +2027,7 @@ ZEND_API ZEND_COLD void zend_use_of_deprecated_trait(
 ) {
 	zend_string *message_suffix = ZSTR_EMPTY_ALLOC();

-	if (get_deprecation_suffix_from_attribute(trait->attributes, trait, &message_suffix) == FAILURE) {
+	if (get_deprecation_suffix_from_attribute(trait->attributes, 0, trait, &message_suffix) == FAILURE) {
 		return;
 	}

diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c
index a25f236c3c2..9a4e89f28d0 100644
--- a/Zend/zend_opcode.c
+++ b/Zend/zend_opcode.c
@@ -595,18 +595,6 @@ ZEND_API void destroy_op_array(zend_op_array *op_array)
 		efree(op_array->vars);
 	}

-	/* ZEND_ACC_PTR_OPS and ZEND_ACC_OVERRIDE use the same value */
-	if ((op_array->fn_flags & ZEND_ACC_PTR_OPS) && !op_array->function_name) {
-		zend_op *op = op_array->opcodes;
-		zend_op *end = op + op_array->last;
-		while (op < end) {
-			if (op->opcode == ZEND_DECLARE_ATTRIBUTED_CONST) {
-				HashTable *attributes = Z_PTR_P(RT_CONSTANT(op+1, (op+1)->op1));
-				zend_hash_release(attributes);
-			}
-			op++;
-		}
-	}
 	if (op_array->literals) {
 		zval *literal = op_array->literals;
 		zval *end = literal + op_array->last_literal;
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index bc9163d3ba0..00ad5c5ffbb 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -8375,46 +8375,41 @@ ZEND_VM_HANDLER(143, ZEND_DECLARE_CONST, CONST, CONST)
 	ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
 }

-ZEND_VM_HANDLER(210, ZEND_DECLARE_ATTRIBUTED_CONST, CONST, CONST)
+ZEND_VM_HANDLER(210, ZEND_DECLARE_ATTRIBUTED_CONST, CONST, CONST, NUM)
 {
 	USE_OPLINE
 	zval *name;
 	zval *val;
-	zend_constant c, *registered;
+	zend_attributed_constant c;
+	zend_constant *registered;

 	SAVE_OPLINE();
 	name  = GET_OP1_ZVAL_PTR(BP_VAR_R);
 	val   = GET_OP2_ZVAL_PTR(BP_VAR_R);

-	ZVAL_COPY(&c.value, val);
-	if (Z_OPT_TYPE(c.value) == IS_CONSTANT_AST) {
-		if (UNEXPECTED(zval_update_constant_ex(&c.value, EX(func)->op_array.scope) != SUCCESS)) {
-			zval_ptr_dtor_nogc(&c.value);
+	ZVAL_COPY(&c.constant.value, val);
+	if (Z_OPT_TYPE(c.constant.value) == IS_CONSTANT_AST) {
+		if (UNEXPECTED(zval_update_constant_ex(&c.constant.value, EX(func)->op_array.scope) != SUCCESS)) {
+			zval_ptr_dtor_nogc(&c.constant.value);
 			FREE_OP1();
 			FREE_OP2();
 			HANDLE_EXCEPTION();
 		}
 	}
 	/* non persistent, case sensitive */
-	ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
-	c.name = zend_string_copy(Z_STR_P(name));
+	ZEND_CONSTANT_SET_FLAGS(&c.constant, CONST_ATTRIBUTED, PHP_USER_CONSTANT);
+	c.constant.name = zend_string_copy(Z_STR_P(name));
+	c.attributes_offset = opline->extended_value;

-	registered = zend_register_constant(&c);
-	if (registered == NULL) {
-		FREE_OP1();
-		FREE_OP2();
-		/* two opcodes used, second one is the data with attributes */
-		ZEND_VM_NEXT_OPCODE_EX(1, 2);
+	registered = zend_register_constant(&c.constant);
+	if (registered != NULL) {
+		/* The attributes are stored in the main op_array, see zend_compile_const_decl() */
+		zend_constant_add_attributes(registered, EX(func)->op_array.attributes);
 	}

-	HashTable *attributes = Z_PTR_P(GET_OP_DATA_ZVAL_PTR(BP_VAR_R));
-	ZEND_ASSERT(attributes != NULL);
-	zend_constant_add_attributes(registered, attributes);
-
 	FREE_OP1();
 	FREE_OP2();
-	/* two opcodes used, second one is the data with attributes */
-	ZEND_VM_NEXT_OPCODE_EX(1, 2);
+	ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
 }

 ZEND_VM_HANDLER(142, ZEND_DECLARE_LAMBDA_FUNCTION, UNUSED, NUM, NUM|CACHE_SLOT)
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 4e2557f2086..406e2e416ca 100644
Binary files a/Zend/zend_vm_execute.h and b/Zend/zend_vm_execute.h differ
diff --git a/Zend/zend_vm_opcodes.c b/Zend/zend_vm_opcodes.c
index cc14862ebed..f6eb53477da 100644
Binary files a/Zend/zend_vm_opcodes.c and b/Zend/zend_vm_opcodes.c differ
diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c
index f71fd287ee2..2b7f27dd4ca 100644
--- a/ext/opcache/jit/zend_jit_ir.c
+++ b/ext/opcache/jit/zend_jit_ir.c
@@ -4182,7 +4182,6 @@ static int zend_jit_handler(zend_jit_ctx *jit, const zend_op *opline, int may_th
 		case ZEND_ASSIGN_STATIC_PROP_REF:
 		case ZEND_ASSIGN_OBJ_REF:
 		case ZEND_FRAMELESS_ICALL_3:
-		case ZEND_DECLARE_ATTRIBUTED_CONST:
 			zend_jit_set_last_valid_opline(jit, opline + 2);
 			break;
 		default:
diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c
index a344f4e1ea8..156bfd74e8c 100644
--- a/ext/opcache/jit/zend_jit_trace.c
+++ b/ext/opcache/jit/zend_jit_trace.c
@@ -629,7 +629,6 @@ static zend_always_inline int zend_jit_trace_op_len(const zend_op *opline)
 		case ZEND_ASSIGN_OBJ_REF:
 		case ZEND_ASSIGN_STATIC_PROP_REF:
 		case ZEND_FRAMELESS_ICALL_3:
-		case ZEND_DECLARE_ATTRIBUTED_CONST:
 			return 2; /* OP_DATA */
 		case ZEND_RECV_INIT:
 			len = 1;
diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c
index 1235b1fc89f..40be83d1ec6 100644
--- a/ext/opcache/zend_file_cache.c
+++ b/ext/opcache/zend_file_cache.c
@@ -247,13 +247,6 @@ static void zend_file_cache_unserialize_func(zval                    *zv,
                                              zend_persistent_script  *script,
                                              void                    *buf);

-static void zend_file_cache_serialize_attribute(zval                     *zv,
-                                                zend_persistent_script   *script,
-                                                zend_file_cache_metainfo *info,
-                                                void                     *buf);
-
-static void zend_file_cache_unserialize_attribute(zval *zv, zend_persistent_script *script, void *buf);
-
 static void *zend_file_cache_serialize_interned(zend_string              *str,
                                                 zend_file_cache_metainfo *info)
 {
@@ -444,9 +437,6 @@ static void zend_file_cache_serialize_zval(zval                     *zv,
 			/* Used by static properties. */
 			SERIALIZE_PTR(Z_INDIRECT_P(zv));
 			break;
-		case IS_PTR:
-			/* Used by attributes on constants, will be handled separately */
-			break;
 		default:
 			ZEND_ASSERT(Z_TYPE_P(zv) < IS_STRING);
 			break;
@@ -566,17 +556,6 @@ static void zend_file_cache_serialize_op_array(zend_op_array            *op_arra
 		UNSERIALIZE_PTR(opline);
 		end = opline + op_array->last;
 		while (opline < end) {
-			if (opline->opcode == ZEND_OP_DATA
-				&& (opline-1)->opcode == ZEND_DECLARE_ATTRIBUTED_CONST
-			) {
-				zval *literal = RT_CONSTANT(opline, opline->op1);
-#if ZEND_USE_ABS_CONST_ADDR
-				SERIALIZE_PTR(literal);
-				UNSERIALIZE_PTR(literal);
-#endif
-				SERIALIZE_ATTRIBUTES(Z_PTR_P(literal));
-			}
-
 #if ZEND_USE_ABS_CONST_ADDR
 			if (opline->op1_type == IS_CONST) {
 				SERIALIZE_PTR(opline->op1.zv);
@@ -1361,9 +1340,6 @@ static void zend_file_cache_unserialize_zval(zval                    *zv,
 			/* Used by static properties. */
 			UNSERIALIZE_PTR(Z_INDIRECT_P(zv));
 			break;
-		case IS_PTR:
-			/* Used by attributes on constants, will be handled separately */
-			break;
 		default:
 			ZEND_ASSERT(Z_TYPE_P(zv) < IS_STRING);
 			break;
@@ -1535,13 +1511,6 @@ static void zend_file_cache_unserialize_op_array(zend_op_array           *op_arr
 			}
 #endif

-			if (opline->opcode == ZEND_OP_DATA
-				&& (opline-1)->opcode == ZEND_DECLARE_ATTRIBUTED_CONST
-			) {
-				zval *literal = RT_CONSTANT(opline, opline->op1);
-				UNSERIALIZE_ATTRIBUTES(Z_PTR_P(literal));
-			}
-
 			if (opline->opcode == ZEND_CALLABLE_CONVERT_PARTIAL) {
 				if (script->corrupted) {
 					opline->extended_value &= ~ZEND_PARTIAL_CACHEABLE_IN_SHM;
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index 84043ed0450..48d2bca4415 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -290,8 +290,6 @@ static void zend_persist_zval(zval *z)
 				efree(old_ref);
 			}
 			break;
-		case IS_PTR:
-			break;
 		default:
 			ZEND_ASSERT(Z_TYPE_P(z) < IS_STRING);
 			break;
@@ -674,13 +672,6 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
 				}
 			}
 #endif
-			if (opline->opcode == ZEND_OP_DATA && (opline-1)->opcode == ZEND_DECLARE_ATTRIBUTED_CONST) {
-				zval *literal = RT_CONSTANT(opline, opline->op1);
-				HashTable *attributes = Z_PTR_P(literal);
-				attributes = zend_persist_attributes(attributes);
-				ZVAL_PTR(literal, attributes);
-			}
-
 			if (opline->opcode == ZEND_CALLABLE_CONVERT_PARTIAL) {
 				if (!ZCG(current_persistent_script)->corrupted) {
 					opline->extended_value |= ZEND_PARTIAL_CACHEABLE_IN_SHM;
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index 71398024e7c..8e828746964 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -163,8 +163,6 @@ static void zend_persist_zval_calc(zval *z)
 				}
 			}
 			break;
-		case IS_PTR:
-			break;
 		default:
 			ZEND_ASSERT(Z_TYPE_P(z) < IS_STRING);
 			break;
@@ -275,19 +273,6 @@ static void zend_persist_op_array_calc_ex(zend_op_array *op_array)
 	zend_shared_alloc_register_xlat_entry(op_array->opcodes, op_array->opcodes);
 	ADD_SIZE(sizeof(zend_op) * op_array->last);

-	/* ZEND_ACC_PTR_OPS and ZEND_ACC_OVERRIDE use the same value */
-	if ((op_array->fn_flags & ZEND_ACC_PTR_OPS) && !op_array->function_name) {
-		zend_op *op = op_array->opcodes;
-		const zend_op *end = op + op_array->last;
-		while (op < end) {
-			if (op->opcode == ZEND_DECLARE_ATTRIBUTED_CONST) {
-				HashTable *attributes = Z_PTR_P(RT_CONSTANT(op+1, (op+1)->op1));
-				zend_persist_attributes_calc(attributes);
-			}
-			op++;
-		}
-	}
-
 	if (op_array->filename) {
 		ADD_STRING(op_array->filename);
 	}
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 311208e419f..171770258af 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -8163,7 +8163,7 @@ ZEND_METHOD(ReflectionConstant, getAttributes)
 	GET_REFLECTION_OBJECT_PTR(const_);

 	reflect_attributes(INTERNAL_FUNCTION_PARAM_PASSTHRU,
-		const_->attributes, 0, NULL, ZEND_ATTRIBUTE_TARGET_CONST,
+		const_->attributes, zend_constant_attributes_offset(const_), NULL, ZEND_ATTRIBUTE_TARGET_CONST,
 		const_->filename);
 }