diff --git a/Zend/tests/int_static_prop_name.phpt b/Zend/tests/int_static_prop_name.phpt new file mode 100644 index 00000000000..bfdfc420529 --- /dev/null +++ b/Zend/tests/int_static_prop_name.phpt @@ -0,0 +1,43 @@ +--TEST-- +Using an integer as a static property name +--FILE-- +getMessage(), "\n"; +} + +try { + var_dump(Foo::${(int) 42}); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +try { + var_dump(Foo::${(int) $n}); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +int(24) +int(24) +int(24) +Access to undeclared static property: Foo::$42 +Access to undeclared static property: Foo::$42 +Access to undeclared static property: Foo::$42 + diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index dd9c5a44de2..a87797bca55 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2616,6 +2616,7 @@ zend_op *zend_compile_static_prop_common(znode *result, zend_ast *ast, uint32_t opline = zend_emit_op(result, ZEND_FETCH_STATIC_PROP_R, &prop_node, NULL); } if (opline->op1_type == IS_CONST) { + convert_to_string(CT_CONSTANT(opline->op1)); zend_alloc_polymorphic_cache_slot(opline->op1.constant); } if (class_node.op_type == IS_CONST) { diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 45fd6df4cb0..0fc70a307d3 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1672,6 +1672,9 @@ ZEND_VM_HELPER(zend_fetch_static_prop_helper, CONST|TMPVAR|CV, UNUSED|CONST|VAR, } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if (OP1_TYPE != IS_CONST) { + zend_string_release(name); + } FREE_OP1(); HANDLE_EXCEPTION(); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index f466dc12dbb..4742401ef2d 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -5011,6 +5011,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_static_prop_helper_SPEC_ } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if (IS_CONST != IS_CONST) { + zend_string_release(name); + } HANDLE_EXCEPTION(); } @@ -6811,6 +6814,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_static_prop_helper_SPEC_ } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if (IS_CONST != IS_CONST) { + zend_string_release(name); + } HANDLE_EXCEPTION(); } @@ -7347,6 +7353,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_static_prop_helper_SPEC_ } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if (IS_CONST != IS_CONST) { + zend_string_release(name); + } HANDLE_EXCEPTION(); } @@ -31604,6 +31613,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_static_prop_helper_SPEC_ } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if (IS_CV != IS_CONST) { + zend_string_release(name); + } HANDLE_EXCEPTION(); } @@ -33721,6 +33733,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_static_prop_helper_SPEC_ } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if (IS_CV != IS_CONST) { + zend_string_release(name); + } HANDLE_EXCEPTION(); } @@ -34704,6 +34719,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_static_prop_helper_SPEC_ } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if (IS_CV != IS_CONST) { + zend_string_release(name); + } HANDLE_EXCEPTION(); } @@ -41959,6 +41977,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_static_prop_helper_SPEC_ } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if ((IS_TMP_VAR|IS_VAR) != IS_CONST) { + zend_string_release(name); + } zval_ptr_dtor_nogc(free_op1); HANDLE_EXCEPTION(); } @@ -42857,6 +42878,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_static_prop_helper_SPEC_ } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if ((IS_TMP_VAR|IS_VAR) != IS_CONST) { + zend_string_release(name); + } zval_ptr_dtor_nogc(free_op1); HANDLE_EXCEPTION(); } @@ -43305,6 +43329,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_static_prop_helper_SPEC_ } retval = zend_std_get_static_property(ce, name, 0); if (UNEXPECTED(EG(exception))) { + if ((IS_TMP_VAR|IS_VAR) != IS_CONST) { + zend_string_release(name); + } zval_ptr_dtor_nogc(free_op1); HANDLE_EXCEPTION(); } diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index 3d238acd850..3aaae5b9158 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -134,6 +134,10 @@ static inline void drop_leading_backslash(zval *val) { } } +static inline void alloc_cache_slots_op1(zend_op_array *op_array, zend_op *opline, uint32_t num) { + Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->cache_size; + op_array->cache_size += num * sizeof(void *); +} static inline void alloc_cache_slots_op2(zend_op_array *op_array, zend_op *opline, uint32_t num) { Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; op_array->cache_size += num * sizeof(void *); @@ -162,7 +166,7 @@ int zend_optimizer_update_op1_const(zend_op_array *op_array, case ZEND_FREE: MAKE_NOP(opline); zval_dtor(val); - break; + return 1; case ZEND_INIT_STATIC_METHOD_CALL: case ZEND_CATCH: case ZEND_FETCH_CONSTANT: @@ -170,27 +174,40 @@ int zend_optimizer_update_op1_const(zend_op_array *op_array, case ZEND_DEFINED: case ZEND_NEW: REQUIRES_STRING(val); - ZEND_OP1_TYPE(opline) = IS_CONST; drop_leading_backslash(val); opline->op1.constant = zend_optimizer_add_literal(op_array, val); - zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline))); - Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->cache_size; - op_array->cache_size += sizeof(void*); + alloc_cache_slots_op1(op_array, opline, 1); zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); break; + case ZEND_FETCH_STATIC_PROP_R: + case ZEND_FETCH_STATIC_PROP_W: + case ZEND_FETCH_STATIC_PROP_RW: + case ZEND_FETCH_STATIC_PROP_IS: + case ZEND_FETCH_STATIC_PROP_UNSET: + case ZEND_FETCH_STATIC_PROP_FUNC_ARG: + TO_STRING_NOWARN(val); + opline->op1.constant = zend_optimizer_add_literal(op_array, val); + alloc_cache_slots_op1(op_array, opline, 2); + break; case ZEND_CONCAT: case ZEND_FAST_CONCAT: + case ZEND_FETCH_R: + case ZEND_FETCH_W: + case ZEND_FETCH_RW: + case ZEND_FETCH_IS: + case ZEND_FETCH_UNSET: + case ZEND_FETCH_FUNC_ARG: TO_STRING_NOWARN(val); /* break missing intentionally */ default: - ZEND_OP1_TYPE(opline) = IS_CONST; opline->op1.constant = zend_optimizer_add_literal(op_array, val); - if (Z_TYPE_P(val) == IS_STRING) { - zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline))); - } break; } + ZEND_OP1_TYPE(opline) = IS_CONST; + if (Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING) { + zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline))); + } return 1; }