Skip to content

Commit 386ab1d

Browse files
committed
Revert "Fix infinite recursion on deprecated attribute evaluation"
This reverts commit 272f7f7. Reverts GH-17712 for the PHP-8.4 branch. This will be reapplied later with a fix for GH-18463 (GH-18464).
1 parent e18498e commit 386ab1d

File tree

8 files changed

+9
-73
lines changed

8 files changed

+9
-73
lines changed

Zend/tests/attributes/deprecated/class_constants/gh17711.phpt

-28
This file was deleted.

Zend/zend_API.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ ZEND_API HashTable *zend_separate_class_constants_table(zend_class_entry *class_
14391439

14401440
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&class_type->constants_table, key, c) {
14411441
if (c->ce == class_type) {
1442-
if (Z_TYPE(c->value) == IS_CONSTANT_AST || (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_DEPRECATED)) {
1442+
if (Z_TYPE(c->value) == IS_CONSTANT_AST) {
14431443
new_c = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
14441444
memcpy(new_c, c, sizeof(zend_class_constant));
14451445
c = new_c;

Zend/zend_compile.c

-4
Original file line numberDiff line numberDiff line change
@@ -8822,10 +8822,6 @@ static void zend_compile_class_const_decl(zend_ast *ast, uint32_t flags, zend_as
88228822

88238823
if (deprecated) {
88248824
ZEND_CLASS_CONST_FLAGS(c) |= ZEND_ACC_DEPRECATED;
8825-
/* For deprecated constants, we need to flag the zval for recursion
8826-
* detection. Make sure the zval is separated out of shm. */
8827-
ce->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;
8828-
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
88298825
}
88308826
}
88318827
}

Zend/zend_constants.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,8 @@ ZEND_API zval *zend_get_class_constant_ex(zend_string *class_name, zend_string *
353353
}
354354

355355
if (UNEXPECTED(ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_DEPRECATED)) {
356-
if ((flags & ZEND_FETCH_CLASS_SILENT) == 0 && !CONST_IS_RECURSIVE(c)) {
357-
CONST_PROTECT_RECURSION(c);
356+
if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
358357
zend_deprecated_class_constant(c, constant_name);
359-
CONST_UNPROTECT_RECURSION(c);
360358
if (EG(exception)) {
361359
goto failure;
362360
}

Zend/zend_constants.h

-11
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@
2727
#define CONST_NO_FILE_CACHE (1<<1) /* Can't be saved in file cache */
2828
#define CONST_DEPRECATED (1<<2) /* Deprecated */
2929
#define CONST_OWNED (1<<3) /* constant should be destroyed together with class */
30-
#define CONST_RECURSIVE (1<<4) /* Recursion protection for constant evaluation */
31-
32-
#define CONST_IS_RECURSIVE(c) (Z_CONSTANT_FLAGS((c)->value) & CONST_RECURSIVE)
33-
#define CONST_PROTECT_RECURSION(c) \
34-
do { \
35-
Z_CONSTANT_FLAGS((c)->value) |= CONST_RECURSIVE; \
36-
} while (0)
37-
#define CONST_UNPROTECT_RECURSION(c) \
38-
do { \
39-
Z_CONSTANT_FLAGS((c)->value) &= ~CONST_RECURSIVE; \
40-
} while (0)
4130

4231
#define PHP_USER_CONSTANT 0x7fffff /* a constant defined in user space */
4332

Zend/zend_vm_def.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -6094,10 +6094,8 @@ ZEND_VM_HANDLER(181, ZEND_FETCH_CLASS_CONSTANT, VAR|CONST|UNUSED|CLASS_FETCH, CO
60946094
}
60956095

60966096
bool is_constant_deprecated = ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_DEPRECATED;
6097-
if (UNEXPECTED(is_constant_deprecated) && !CONST_IS_RECURSIVE(c)) {
6098-
CONST_PROTECT_RECURSION(c);
6097+
if (UNEXPECTED(is_constant_deprecated)) {
60996098
zend_deprecated_class_constant(c, constant_name);
6100-
CONST_UNPROTECT_RECURSION(c);
61016099

61026100
if (EG(exception)) {
61036101
ZVAL_UNDEF(EX_VAR(opline->result.var));

Zend/zend_vm_execute.h

+6-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/opcache/ZendAccelerator.c

-5
Original file line numberDiff line numberDiff line change
@@ -3800,11 +3800,6 @@ static bool preload_try_resolve_constants(zend_class_entry *ce)
38003800
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) {
38013801
val = &c->value;
38023802
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
3803-
/* For deprecated constants, we need to flag the zval for recursion
3804-
* detection. Make sure the zval is separated out of shm. */
3805-
if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_DEPRECATED) {
3806-
ok = false;
3807-
}
38083803
if (EXPECTED(zend_update_class_constant(c, key, c->ce) == SUCCESS)) {
38093804
was_changed = changed = true;
38103805
} else {

0 commit comments

Comments
 (0)