@@ -4083,10 +4083,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
40834083 zend_op * opline ;
40844084 uint32_t check_op_number = get_next_op_number ();
40854085
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-
40904086 zend_emit_op (NULL , ZEND_ASSERT_CHECK , NULL , NULL );
40914087
40924088 if (fbc && fbc_is_finalized (fbc )) {
@@ -4120,8 +4116,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
41204116 opline = & CG (active_op_array )-> opcodes [check_op_number ];
41214117 opline -> op2 .opline_num = get_next_op_number ();
41224118 SET_NODE (opline -> result , result );
4123-
4124- CG (memoize_mode ) = orig_memoize_mode ;
41254119 } else {
41264120 if (!fbc ) {
41274121 zend_string_release_ex (name , 0 );
@@ -4453,7 +4447,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
44534447 if (runtime_resolution ) {
44544448 if (zend_string_equals_literal_ci (zend_ast_get_str (name_ast ), "assert" )
44554449 && !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+ }
44574458 } else {
44584459 zend_compile_ns_call (result , & name_node , args_ast );
44594460 }
@@ -4472,7 +4473,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
44724473
44734474 /* Special assert() handling should apply independently of compiler flags. */
44744475 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+ }
44764484 zend_string_release (lcname );
44774485 zval_ptr_dtor (& name_node .u .constant );
44784486 return ;
0 commit comments