@@ -4095,10 +4095,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
4095
4095
zend_op * opline ;
4096
4096
uint32_t check_op_number = get_next_op_number ();
4097
4097
4098
- /* Assert expression may not be memoized and reused as it may not actually be evaluated. */
4099
- int orig_memoize_mode = CG (memoize_mode );
4100
- CG (memoize_mode ) = ZEND_MEMOIZE_NONE ;
4101
-
4102
4098
zend_emit_op (NULL , ZEND_ASSERT_CHECK , NULL , NULL );
4103
4099
4104
4100
if (fbc && fbc_is_finalized (fbc )) {
@@ -4132,8 +4128,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
4132
4128
opline = & CG (active_op_array )-> opcodes [check_op_number ];
4133
4129
opline -> op2 .opline_num = get_next_op_number ();
4134
4130
SET_NODE (opline -> result , result );
4135
-
4136
- CG (memoize_mode ) = orig_memoize_mode ;
4137
4131
} else {
4138
4132
if (!fbc ) {
4139
4133
zend_string_release_ex (name , 0 );
@@ -4465,7 +4459,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
4465
4459
if (runtime_resolution ) {
4466
4460
if (zend_string_equals_literal_ci (zend_ast_get_str (name_ast ), "assert" )
4467
4461
&& !is_callable_convert ) {
4468
- zend_compile_assert (result , zend_ast_get_list (args_ast ), Z_STR (name_node .u .constant ), NULL , ast -> lineno );
4462
+ if (CG (memoize_mode ) == ZEND_MEMOIZE_NONE ) {
4463
+ zend_compile_assert (result , zend_ast_get_list (args_ast ), Z_STR (name_node .u .constant ), NULL , ast -> lineno );
4464
+ } else {
4465
+ /* We want to always memoize assert calls, even if they are positioned in
4466
+ * write-context. This prevents memoizing their arguments that might not be
4467
+ * evaluated if assertions are disabled, using a TMPVAR that wasn't initialized. */
4468
+ zend_compile_memoized_expr (result , ast );
4469
+ }
4469
4470
} else {
4470
4471
zend_compile_ns_call (result , & name_node , args_ast , ast -> lineno );
4471
4472
}
@@ -4484,7 +4485,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
4484
4485
4485
4486
/* Special assert() handling should apply independently of compiler flags. */
4486
4487
if (fbc && zend_string_equals_literal (lcname , "assert" ) && !is_callable_convert ) {
4487
- zend_compile_assert (result , zend_ast_get_list (args_ast ), lcname , fbc , ast -> lineno );
4488
+ if (CG (memoize_mode ) == ZEND_MEMOIZE_NONE ) {
4489
+ zend_compile_assert (result , zend_ast_get_list (args_ast ), lcname , fbc , ast -> lineno );
4490
+ } else {
4491
+ /* We want to always memoize assert calls, even if they are positioned in
4492
+ * write-context. This prevents memoizing their arguments that might not be
4493
+ * evaluated if assertions are disabled, using a TMPVAR that wasn't initialized. */
4494
+ zend_compile_memoized_expr (result , ast );
4495
+ }
4488
4496
zend_string_release (lcname );
4489
4497
zval_ptr_dtor (& name_node .u .constant );
4490
4498
return ;
0 commit comments