@@ -4083,10 +4083,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
4083
4083
zend_op * opline ;
4084
4084
uint32_t check_op_number = get_next_op_number ();
4085
4085
4086
- /* Assert expression may not be memoized and reused as it may not actually be evaluated. */
4087
- int orig_memoize_mode = CG (memoize_mode );
4088
- CG (memoize_mode ) = ZEND_MEMOIZE_NONE ;
4089
-
4090
4086
zend_emit_op (NULL , ZEND_ASSERT_CHECK , NULL , NULL );
4091
4087
4092
4088
if (fbc && fbc_is_finalized (fbc )) {
@@ -4120,8 +4116,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
4120
4116
opline = & CG (active_op_array )-> opcodes [check_op_number ];
4121
4117
opline -> op2 .opline_num = get_next_op_number ();
4122
4118
SET_NODE (opline -> result , result );
4123
-
4124
- CG (memoize_mode ) = orig_memoize_mode ;
4125
4119
} else {
4126
4120
if (!fbc ) {
4127
4121
zend_string_release_ex (name , 0 );
@@ -4453,7 +4447,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
4453
4447
if (runtime_resolution ) {
4454
4448
if (zend_string_equals_literal_ci (zend_ast_get_str (name_ast ), "assert" )
4455
4449
&& !is_callable_convert ) {
4456
- zend_compile_assert (result , zend_ast_get_list (args_ast ), Z_STR (name_node .u .constant ), NULL );
4450
+ if (CG (memoize_mode ) == ZEND_MEMOIZE_NONE ) {
4451
+ zend_compile_assert (result , zend_ast_get_list (args_ast ), Z_STR (name_node .u .constant ), NULL );
4452
+ } else {
4453
+ /* We want to always memoize assert calls, even if they are positioned in
4454
+ * write-context. This prevents memoizing their arguments that might not be
4455
+ * evaluated if assertions are disabled, using a TMPVAR that wasn't initialized. */
4456
+ zend_compile_memoized_expr (result , ast );
4457
+ }
4457
4458
} else {
4458
4459
zend_compile_ns_call (result , & name_node , args_ast );
4459
4460
}
@@ -4472,7 +4473,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
4472
4473
4473
4474
/* Special assert() handling should apply independently of compiler flags. */
4474
4475
if (fbc && zend_string_equals_literal (lcname , "assert" ) && !is_callable_convert ) {
4475
- zend_compile_assert (result , zend_ast_get_list (args_ast ), lcname , fbc );
4476
+ if (CG (memoize_mode ) == ZEND_MEMOIZE_NONE ) {
4477
+ zend_compile_assert (result , zend_ast_get_list (args_ast ), lcname , fbc );
4478
+ } else {
4479
+ /* We want to always memoize assert calls, even if they are positioned in
4480
+ * write-context. This prevents memoizing their arguments that might not be
4481
+ * evaluated if assertions are disabled, using a TMPVAR that wasn't initialized. */
4482
+ zend_compile_memoized_expr (result , ast );
4483
+ }
4476
4484
zend_string_release (lcname );
4477
4485
zval_ptr_dtor (& name_node .u .constant );
4478
4486
return ;
0 commit comments