Skip to content

BUG: Using never as return type breaks built proxies #3451

@kdambekalns

Description

@kdambekalns

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Imagine an action like this:

public function testAction(): never
{
    // some code here
    exit();
}

The proxy method built for this does return, leading to an error:

PHP Fatal error: A never-returning function must not return in /…/Data/Temporary/Production/SubContextLive/Cache/Code/Flow_Object_Classes/Acme_Foo_SomeController.php on line 123

The code looks like this (depending on advices being present):

public function testAction() : never
    {
 
        if (isset($this->Flow_Aop_Proxy_methodIsInAdviceMode['testAction'])) {
            $result = parent::testAction();
 
        } else {
            $this->Flow_Aop_Proxy_methodIsInAdviceMode['testAction'] = true;
            try {
 
                $methodArguments = [];
 
                $adviceChains = $this->Flow_Aop_Proxy_getAdviceChains('testAction');
                $adviceChain = $adviceChains['Neos\Flow\Aop\Advice\AroundAdvice'];
                $adviceChain->rewind();
                $joinPoint = new \Neos\Flow\Aop\JoinPoint($this, 'Acme\Foo\Controller\SomeController', 'testAction', $methodArguments, $adviceChain);
                $result = $adviceChain->proceed($joinPoint);
                $methodArguments = $joinPoint->getMethodArguments();
 
            } catch (\Exception $exception) {
                unset($this->Flow_Aop_Proxy_methodIsInAdviceMode['testAction']);
                throw $exception;
            }
            unset($this->Flow_Aop_Proxy_methodIsInAdviceMode['testAction']);
        }
        return $result;
    }

Expected Behavior

The action can be called just fine, the proxy method is built correctly. That means, it should not return, as never must not return:

never is a return-only type indicating the function does not terminate. This means that it either calls exit(), throws an exception, or is an infinite loop.

Any AOP "after" this must not be built (useless), "around" could skip anything handling the return value (useless), assigning $result is useless and the proxy itself must not return at all. Which might render any AOP useless (unless the proxy changes the return type, which is impossible unless the original is changed, too, which would be a very bad idea).

Steps To Reproduce

No response

Environment

- Flow: 8.3
- PHP: 8.3

Anything else?

Workaround for now: Do not use never in your code.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions