@@ -4223,10 +4223,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
4223
4223
zend_op * opline ;
4224
4224
uint32_t check_op_number = get_next_op_number ();
4225
4225
4226
- /* Assert expression may not be memoized and reused as it may not actually be evaluated. */
4227
- int orig_memoize_mode = CG (memoize_mode );
4228
- CG (memoize_mode ) = ZEND_MEMOIZE_NONE ;
4229
-
4230
4226
zend_emit_op (NULL , ZEND_ASSERT_CHECK , NULL , NULL );
4231
4227
4232
4228
if (fbc && fbc_is_finalized (fbc )) {
@@ -4260,8 +4256,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
4260
4256
opline = & CG (active_op_array )-> opcodes [check_op_number ];
4261
4257
opline -> op2 .opline_num = get_next_op_number ();
4262
4258
SET_NODE (opline -> result , result );
4263
-
4264
- CG (memoize_mode ) = orig_memoize_mode ;
4265
4259
} else {
4266
4260
if (!fbc ) {
4267
4261
zend_string_release_ex (name , 0 );
@@ -4593,7 +4587,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
4593
4587
if (runtime_resolution ) {
4594
4588
if (zend_string_equals_literal_ci (zend_ast_get_str (name_ast ), "assert" )
4595
4589
&& !is_callable_convert ) {
4596
- zend_compile_assert (result , zend_ast_get_list (args_ast ), Z_STR (name_node .u .constant ), NULL , ast -> lineno );
4590
+ if (CG (memoize_mode ) == ZEND_MEMOIZE_NONE ) {
4591
+ zend_compile_assert (result , zend_ast_get_list (args_ast ), Z_STR (name_node .u .constant ), NULL , ast -> lineno );
4592
+ } else {
4593
+ /* We want to always memoize assert calls, even if they are positioned in
4594
+ * write-context. This prevents memoizing their arguments that might not be
4595
+ * evaluated if assertions are disabled, using a TMPVAR that wasn't initialized. */
4596
+ zend_compile_memoized_expr (result , ast );
4597
+ }
4597
4598
} else {
4598
4599
zend_compile_ns_call (result , & name_node , args_ast , ast -> lineno );
4599
4600
}
@@ -4612,7 +4613,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
4612
4613
4613
4614
/* Special assert() handling should apply independently of compiler flags. */
4614
4615
if (fbc && zend_string_equals_literal (lcname , "assert" ) && !is_callable_convert ) {
4615
- zend_compile_assert (result , zend_ast_get_list (args_ast ), lcname , fbc , ast -> lineno );
4616
+ if (CG (memoize_mode ) == ZEND_MEMOIZE_NONE ) {
4617
+ zend_compile_assert (result , zend_ast_get_list (args_ast ), lcname , fbc , ast -> lineno );
4618
+ } else {
4619
+ /* We want to always memoize assert calls, even if they are positioned in
4620
+ * write-context. This prevents memoizing their arguments that might not be
4621
+ * evaluated if assertions are disabled, using a TMPVAR that wasn't initialized. */
4622
+ zend_compile_memoized_expr (result , ast );
4623
+ }
4616
4624
zend_string_release (lcname );
4617
4625
zval_ptr_dtor (& name_node .u .constant );
4618
4626
return ;
0 commit comments