yiisoft / yii

Yii PHP Framework 1.1.x

Home Page:http://www.yiiframework.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error using UnionTypes in action declarations

crisps-for-breakfast opened this issue · comments

commented

I arguably shouldn't be doing this, but there seems to be a PHP 8.x compatibility issue when using UnionTypes in action declarations

What steps will reproduce the problem?

Use union type in action function declaration public function action(int|string $hello);

What is the expected result?

Not sure, maybe the same as when no type is declared, or some new type handling logic

What do you get instead?

Call to undefined method ReflectionUnionType::getName()
composer_packages/yiisoft/yii/framework/web/actions/CAction.php(98)

Additional info

Q A
Yii version 1.1.28
PHP version 8.1.13
Operating system MacOS Monterey 12.6.3

@crisps-for-breakfast I'm not sure declaring union types in a web controller action makes sense, but this should be easy enough to fix. All CAction is trying to do here is determine if you are declaring the parameter as an array or not: https://github.com/yiisoft/yii/blob/master/framework/web/actions/CAction.php#L98 (perhaps with a similar solution as Yii 2: https://github.com/yiisoft/yii2/blob/25eed6fe1c51bcf04c55879fa957ec4feeaa9759/framework/web/Controller.php#L137)