@@ -5673,21 +5673,25 @@ static zend_bool zend_is_valid_default_value(zend_type type, zval *value)
56735673 return 0 ;
56745674}
56755675
5676- void zend_compile_params (zend_ast * ast , zend_ast * return_type_ast ) /* {{{ */
5676+ void zend_compile_params (zend_ast * ast , zend_ast * return_type_ast , uint32_t fallback_return_type ) /* {{{ */
56775677{
56785678 zend_ast_list * list = zend_ast_get_list (ast );
56795679 uint32_t i ;
56805680 zend_op_array * op_array = CG (active_op_array );
56815681 zend_arg_info * arg_infos ;
56825682
5683- if (return_type_ast ) {
5683+ if (return_type_ast || fallback_return_type ) {
56845684 /* Use op_array->arg_info[-1] for return type */
56855685 arg_infos = safe_emalloc (sizeof (zend_arg_info ), list -> children + 1 , 0 );
56865686 arg_infos -> name = NULL ;
5687- arg_infos -> type = zend_compile_typename (
5688- return_type_ast , /* force_allow_null */ 0 , /* use_arena */ 0 );
5689- ZEND_TYPE_FULL_MASK (arg_infos -> type ) |= _ZEND_ARG_INFO_FLAGS (
5690- (op_array -> fn_flags & ZEND_ACC_RETURN_REFERENCE ) != 0 , /* is_variadic */ 0 );
5687+ if (return_type_ast ) {
5688+ arg_infos -> type = zend_compile_typename (
5689+ return_type_ast , /* force_allow_null */ 0 , /* use_arena */ 0 );
5690+ ZEND_TYPE_FULL_MASK (arg_infos -> type ) |= _ZEND_ARG_INFO_FLAGS (
5691+ (op_array -> fn_flags & ZEND_ACC_RETURN_REFERENCE ) != 0 , /* is_variadic */ 0 );
5692+ } else {
5693+ arg_infos -> type = (zend_type ) ZEND_TYPE_INIT_CODE (fallback_return_type , 0 , 0 );
5694+ }
56915695 arg_infos ++ ;
56925696 op_array -> fn_flags |= ZEND_ACC_HAS_RETURN_TYPE ;
56935697 } else {
@@ -6167,6 +6171,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
61676171 zend_ast * stmt_ast = decl -> child [2 ];
61686172 zend_ast * return_type_ast = decl -> child [3 ];
61696173 zend_bool is_method = decl -> kind == ZEND_AST_METHOD ;
6174+ zend_bool is___tostring = is_method && CG (active_class_entry )-> __tostring == NULL ;
61706175
61716176 zend_class_entry * orig_class_entry = CG (active_class_entry );
61726177 zend_op_array * orig_op_array = CG (active_op_array );
@@ -6200,6 +6205,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
62006205 if (is_method ) {
62016206 zend_bool has_body = stmt_ast != NULL ;
62026207 zend_begin_method_decl (op_array , decl -> name , has_body );
6208+ is___tostring = is___tostring && CG (active_class_entry )-> __tostring != NULL ;
62036209 } else {
62046210 zend_begin_func_decl (result , op_array , decl , toplevel );
62056211 if (decl -> kind == ZEND_AST_ARROW_FUNC ) {
@@ -6238,7 +6244,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
62386244 zend_stack_push (& CG (loop_var_stack ), (void * ) & dummy_var );
62396245 }
62406246
6241- zend_compile_params (params_ast , return_type_ast );
6247+ zend_compile_params (params_ast , return_type_ast , is___tostring ? IS_STRING : 0 );
62426248 if (CG (active_op_array )-> fn_flags & ZEND_ACC_GENERATOR ) {
62436249 zend_mark_function_as_generator ();
62446250 zend_emit_op (NULL , ZEND_GENERATOR_CREATE , NULL , NULL );
0 commit comments