@@ -5671,21 +5671,25 @@ static zend_bool zend_is_valid_default_value(zend_type type, zval *value)
56715671 return 0 ;
56725672}
56735673
5674- void zend_compile_params (zend_ast * ast , zend_ast * return_type_ast ) /* {{{ */
5674+ void zend_compile_params (zend_ast * ast , zend_ast * return_type_ast , uint32_t fallback_return_type ) /* {{{ */
56755675{
56765676 zend_ast_list * list = zend_ast_get_list (ast );
56775677 uint32_t i ;
56785678 zend_op_array * op_array = CG (active_op_array );
56795679 zend_arg_info * arg_infos ;
56805680
5681- if (return_type_ast ) {
5681+ if (return_type_ast || fallback_return_type ) {
56825682 /* Use op_array->arg_info[-1] for return type */
56835683 arg_infos = safe_emalloc (sizeof (zend_arg_info ), list -> children + 1 , 0 );
56845684 arg_infos -> name = NULL ;
5685- arg_infos -> type = zend_compile_typename (
5686- return_type_ast , /* force_allow_null */ 0 , /* use_arena */ 0 );
5687- ZEND_TYPE_FULL_MASK (arg_infos -> type ) |= _ZEND_ARG_INFO_FLAGS (
5688- (op_array -> fn_flags & ZEND_ACC_RETURN_REFERENCE ) != 0 , /* is_variadic */ 0 );
5685+ if (return_type_ast ) {
5686+ arg_infos -> type = zend_compile_typename (
5687+ return_type_ast , /* force_allow_null */ 0 , /* use_arena */ 0 );
5688+ ZEND_TYPE_FULL_MASK (arg_infos -> type ) |= _ZEND_ARG_INFO_FLAGS (
5689+ (op_array -> fn_flags & ZEND_ACC_RETURN_REFERENCE ) != 0 , /* is_variadic */ 0 );
5690+ } else {
5691+ arg_infos -> type = (zend_type ) ZEND_TYPE_INIT_CODE (fallback_return_type , 0 , 0 );
5692+ }
56895693 arg_infos ++ ;
56905694 op_array -> fn_flags |= ZEND_ACC_HAS_RETURN_TYPE ;
56915695 } else {
@@ -6165,6 +6169,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
61656169 zend_ast * stmt_ast = decl -> child [2 ];
61666170 zend_ast * return_type_ast = decl -> child [3 ];
61676171 zend_bool is_method = decl -> kind == ZEND_AST_METHOD ;
6172+ zend_bool is___tostring = is_method && CG (active_class_entry )-> __tostring == NULL ;
61686173
61696174 zend_class_entry * orig_class_entry = CG (active_class_entry );
61706175 zend_op_array * orig_op_array = CG (active_op_array );
@@ -6198,6 +6203,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
61986203 if (is_method ) {
61996204 zend_bool has_body = stmt_ast != NULL ;
62006205 zend_begin_method_decl (op_array , decl -> name , has_body );
6206+ is___tostring = is___tostring && CG (active_class_entry )-> __tostring != NULL ;
62016207 } else {
62026208 zend_begin_func_decl (result , op_array , decl , toplevel );
62036209 if (decl -> kind == ZEND_AST_ARROW_FUNC ) {
@@ -6236,7 +6242,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
62366242 zend_stack_push (& CG (loop_var_stack ), (void * ) & dummy_var );
62376243 }
62386244
6239- zend_compile_params (params_ast , return_type_ast );
6245+ zend_compile_params (params_ast , return_type_ast , is___tostring ? IS_STRING : 0 );
62406246 if (CG (active_op_array )-> fn_flags & ZEND_ACC_GENERATOR ) {
62416247 zend_mark_function_as_generator ();
62426248 zend_emit_op (NULL , ZEND_GENERATOR_CREATE , NULL , NULL );
0 commit comments