flow-development-collection icon indicating copy to clipboard operation
flow-development-collection copied to clipboard

BUG: Generated proxy method uses wrong return type

Open robertlemke opened this issue 3 years ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

An original class containing an __invoke() method with a return type of mixed results in a auto-generated proxy method with return type ?mixed.

That results in the following error:

Fatal error: Type mixed cannot be marked as nullable since mixed already includes null

Expected Behavior

The proxy method should contain the correct return type (mixed can never be optional).

Steps To Reproduce

Create a class containing the following method:

public function __invoke($objectValue, $args, $_, ResolveInfo $info): mixed
{
}

Protect that method with a security policy, so that a proxy method is generated.

Environment

- Flow: dev-master (56bd731b691270b208423d4cadf4c7c4803d71ec), shortly after the 8.1.1 release
- PHP: 8.1

Anything else?

No response

robertlemke avatar Sep 09 '22 05:09 robertlemke

Woah, probably the result of Flow checking vie reflection of the return type is nullable. Having null in mixed makes that check pass, even though it must not be marked nullable. Awesome insonsistency. 🤷‍♂️

kdambekalns avatar Sep 09 '22 05:09 kdambekalns

Also, judging from

mixed can never be optional

the ? doesn't even mean nullable, but optional. TIL.

kdambekalns avatar Sep 09 '22 05:09 kdambekalns

We need that new / revamped Reflection Service I've been talking about.

robertlemke avatar Sep 09 '22 06:09 robertlemke

We need that new / revamped Reflection Service I've been talking about.

True. But that would still be a special case I would not have anticipated.

kdambekalns avatar Sep 09 '22 06:09 kdambekalns