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

PHPStan configured for php 7.4. accepts php 8.x code #9138

Closed
jacekciach opened this issue Apr 4, 2023 · 3 comments
Closed

PHPStan configured for php 7.4. accepts php 8.x code #9138

jacekciach opened this issue Apr 4, 2023 · 3 comments

Comments

@jacekciach
Copy link

Bug report

PHPStan reports "no errors" in the code that would not run in the required version of PHP (7.4).

The problem was detected in 1.9.17. Updating to 1.10.10 does not solve the issue.

Code snippet that reproduces the problem

<?php // php 7.4

function foo(): mixed
{
    return 'xyz';
}

function bar(): never
{
    throw new \Exception();
}


foo();
bar();

Of course, this code won't run in php 7.4:

PHP Fatal error:  Uncaught TypeError: Return value of foo() must be an instance of mixed, string returned
# phpstan.neon
parameters:
    phpVersion: 70400
    level: 9

Expected output

PHPStan should report errors like:

 ------ ------------------------------------------------------- 
  Line   untitled.php                                           
 ------ ------------------------------------------------------- 
  3      Function foo() has invalid return type mixed.           
  5      Function foo() should return mixed but returns string.  
  8      Function bar() has invalid return type never.
 ------ ------------------------------------------------------- 

but reports "no errors".

The problem occurs both in php 7.4 runtime and php 8.1 runtime.

The problem has a quite big impact on the CI/CD - PHPStan didn't report the problem when a developer declared return type mixed in php 7.4 code.

@mergeable
Copy link

mergeable bot commented Apr 4, 2023

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Duplicate of #6861

@ondrejmirtes ondrejmirtes marked this as a duplicate of #6861 Apr 4, 2023
@github-actions
Copy link

github-actions bot commented May 6, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants