@@ -4095,10 +4095,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
40954095 zend_op * opline ;
40964096 uint32_t check_op_number = get_next_op_number ();
40974097
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-
41024098 zend_emit_op (NULL , ZEND_ASSERT_CHECK , NULL , NULL );
41034099
41044100 if (fbc && fbc_is_finalized (fbc )) {
@@ -4132,8 +4128,6 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
41324128 opline = & CG (active_op_array )-> opcodes [check_op_number ];
41334129 opline -> op2 .opline_num = get_next_op_number ();
41344130 SET_NODE (opline -> result , result );
4135-
4136- CG (memoize_mode ) = orig_memoize_mode ;
41374131 } else {
41384132 if (!fbc ) {
41394133 zend_string_release_ex (name , 0 );
@@ -4465,7 +4459,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
44654459 if (runtime_resolution ) {
44664460 if (zend_string_equals_literal_ci (zend_ast_get_str (name_ast ), "assert" )
44674461 && !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+ }
44694470 } else {
44704471 zend_compile_ns_call (result , & name_node , args_ast , ast -> lineno );
44714472 }
@@ -4484,7 +4485,14 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
44844485
44854486 /* Special assert() handling should apply independently of compiler flags. */
44864487 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+ }
44884496 zend_string_release (lcname );
44894497 zval_ptr_dtor (& name_node .u .constant );
44904498 return ;
0 commit comments