Skip to content

Commit cdb9b06

Browse files
Fix for opcache
Delay compiling the attributes until runtime
1 parent 29f565e commit cdb9b06

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

Zend/zend_compile.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7344,7 +7344,7 @@ static bool zend_is_valid_default_value(zend_type type, zval *value)
73447344
return 0;
73457345
}
73467346

7347-
static void zend_compile_attributes(
7347+
void zend_compile_attributes(
73487348
HashTable **attributes, zend_ast *ast, uint32_t offset, uint32_t target, uint32_t promoted
73497349
) /* {{{ */ {
73507350
zend_attribute *attr;
@@ -7386,8 +7386,10 @@ static void zend_compile_attributes(
73867386
}
73877387
}
73887388

7389-
uint32_t flags = (CG(active_op_array)->fn_flags & ZEND_ACC_STRICT_TYPES)
7390-
? ZEND_ATTRIBUTE_STRICT_TYPES : 0;
7389+
uint32_t flags = 0;
7390+
if (CG(active_op_array) && (CG(active_op_array)->fn_flags & ZEND_ACC_STRICT_TYPES)) {
7391+
flags = ZEND_ATTRIBUTE_STRICT_TYPES;
7392+
}
73917393
attr = zend_add_attribute(
73927394
attributes, name, args ? args->children : 0, flags, offset, el->lineno);
73937395
zend_string_release(name);
@@ -9471,11 +9473,9 @@ static void zend_compile_const_decl(zend_ast *ast) /* {{{ */
94719473
}
94729474
ZEND_ASSERT(last_op != NULL);
94739475
last_op->opcode = ZEND_DECLARE_ATTRIBUTED_CONST;
9474-
HashTable *attribs_ht = NULL;
9475-
zend_compile_attributes(&attribs_ht, list->child[1], 0, ZEND_ATTRIBUTE_TARGET_CONST, 0);
94769476
znode attribs_node;
94779477
attribs_node.op_type = IS_CONST;
9478-
ZVAL_PTR(&attribs_node.u.constant, attribs_ht);
9478+
ZVAL_AST(&attribs_node.u.constant, zend_ast_copy(list->child[1]));
94799479
zend_emit_op_data(&attribs_node);
94809480
}
94819481
/* }}}*/

Zend/zend_compile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,10 @@ void zend_assert_valid_class_name(const zend_string *const_name, const char *typ
10061006
zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scope);
10071007
ZEND_API zend_string *zend_type_to_string(zend_type type);
10081008

1009+
void zend_compile_attributes(
1010+
HashTable **attributes, zend_ast *ast, uint32_t offset, uint32_t target, uint32_t promoted
1011+
);
1012+
10091013
/* BEGIN: OPCODES */
10101014

10111015
#include "zend_vm_opcodes.h"

Zend/zend_vm_def.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8280,9 +8280,10 @@ ZEND_VM_HANDLER(210, ZEND_DECLARE_ATTRIBUTED_CONST, CONST, CONST)
82808280
zval *attribs = GET_OP_DATA_ZVAL_PTR(BP_VAR_R);
82818281
zend_constant *registered = zend_get_constant_ptr(c.name);
82828282
ZEND_ASSERT(registered != NULL);
8283-
registered->attributes = Z_PTR_P(attribs);
8283+
zend_ast *ast = Z_ASTVAL_P(attribs);
8284+
zend_compile_attributes(&registered->attributes, ast, 0, ZEND_ATTRIBUTE_TARGET_CONST, 0);
82848285
zend_attribute *deprecated_attribute = zend_get_attribute_str(
8285-
Z_PTR_P(attribs),
8286+
registered->attributes,
82868287
"deprecated",
82878288
sizeof("deprecated")-1
82888289
);

Zend/zend_vm_execute.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)