Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods like sendResponse() should contain never-return typehint #290

janbarasek opened this issue Jul 2, 2021 · 3 comments


Copy link

janbarasek commented Jul 2, 2021


I think methods like sendJson() should contain PHPStan annotation @phpstan-return never-return like this:

 * Sends JSON data to the output.
 * @throws Nette\Application\AbortException
 * @phpstan-return never-return
public function sendJson(mixed $data): void
	$this->sendResponse(new Responses\JsonResponse($data));

Currently, this can generate hundreds of errors when PhpStan reports possible undefined variables. The annotation marks the code after this call as dead.

For example:

public function actionDefault(): void
    if ($this->variable) {
        $a = 1;
    } else {

    echo $a; // generate possible undefined variable, but it is not true

Yes, there is an official extension for PhpStan and Nette framework that does this solution, but it would be good to have native support as well.


Copy link

The official type name is just never.

Copy link

dg commented Jul 2, 2021

@return never seems good, can you send PR?

Copy link
Contributor Author

Solved by #291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

3 participants