@@ -4223,10 +4223,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
42234223 zend_op * opline ;
42244224 uint32_t check_op_number = get_next_op_number ();
42254225
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-
42304226 zend_emit_op (NULL , ZEND_ASSERT_CHECK , NULL , NULL );
42314227
42324228 if (fbc && fbc_is_finalized (fbc )) {
@@ -4260,8 +4256,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
42604256 opline = & CG (active_op_array )-> opcodes [check_op_number ];
42614257 opline -> op2 .opline_num = get_next_op_number ();
42624258 SET_NODE (opline -> result , result );
4263-
4264- CG (memoize_mode ) = orig_memoize_mode ;
42654259 } else {
42664260 if (!fbc ) {
42674261 zend_string_release_ex (name , 0 );
@@ -4593,7 +4587,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
45934587 if (runtime_resolution ) {
45944588 if (zend_string_equals_literal_ci (zend_ast_get_str (name_ast ), "assert" )
45954589 && !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+ }
45974598 } else {
45984599 zend_compile_ns_call (result , & name_node , args_ast , ast -> lineno );
45994600 }
@@ -4612,7 +4613,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
46124613
46134614 /* Special assert() handling should apply independently of compiler flags. */
46144615 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+ }
46164624 zend_string_release (lcname );
46174625 zval_ptr_dtor (& name_node .u .constant );
46184626 return ;
0 commit comments