walkor / walkor/webman

路由映射到控制器方法参数的时候,使用了联合类型,会提示报错 Error: Call to undefined method ReflectionUnionType::getName()

Open
#431 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
2.7k
Forks
251
PR merge metrics
No merged PRs in 30d

Description

PHP版本:8.3.15

路由 config/route.php
```php
Route::get("/$name/read/{id}", [$controller, 'read'])
````
控制器
```php
public function read(Request $request, int|string $id) : Response
{
…………………………
}
```

这里 $id 对应了路由里面的 {id} ,访问的时候会出现
Error: Call to undefined method ReflectionUnionType::getName() in ./vendor/workerman/webman-framework/src/App.php:429

Stack trace:

如果我只用 int 或者 string 修饰 $id ,则不会出现报错。

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the route and controller signature shown in the issue on PHP 8.3.15, then inspect vendor/workerman/webman-framework/src/App.php around line 429 and trace how the controller parameter type is read. The work is done when a union-typed route parameter no longer raises ReflectionUnionType::getName(), while int-only and string-only parameters continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.