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

try/catch improvement idea #3617

Closed
gnutix opened this issue Jul 16, 2020 · 7 comments
Closed

try/catch improvement idea #3617

gnutix opened this issue Jul 16, 2020 · 7 comments

Comments

@gnutix
Copy link

gnutix commented Jul 16, 2020

Everything being inferred after the last possible piece of code that may throw an exception should not have an impact on the catch clause.

Examples :
Correct : https://phpstan.org/r/c33d8ed6-a27a-447c-b8ee-c4d842ee2354
Incorrect : https://phpstan.org/r/3cdc98ed-2e4f-4269-8197-bd1dfaa7ecd2

@ondrejmirtes
Copy link
Member

Yeah, there's a milestone for issues like this: https://github.com/phpstan/phpstan/milestone/11

@phpstan-bot
Copy link
Contributor

@gnutix PHPStan now reports different result with your code snippet:

@@ @@
+PHP 8.0 (1 error)
+==========
+
+7: Parameter #1 $string of function strtolower expects string, int|string given.
+
+PHP 7.1 – 7.4 (1 error)
+==========
+
 7: Parameter #1 $str of function strtolower expects string, int|string given.
Full report

PHP 8.0 (1 error)

Line Error
7 `Parameter #1 $string of function strtolower expects string, int

PHP 7.1 – 7.4 (1 error)

Line Error
7 `Parameter #1 $str of function strtolower expects string, int

@phpstan-bot
Copy link
Contributor

@gnutix PHPStan now reports different result with your code snippet:

@@ @@
+PHP 8.0 (1 error)
+==========
+
+6: Parameter #1 $string of function strtolower expects string, int|string given.
+
+PHP 7.1 – 7.4 (1 error)
+==========
+
 6: Parameter #1 $str of function strtolower expects string, int|string given.
Full report

PHP 8.0 (1 error)

Line Error
6 `Parameter #1 $string of function strtolower expects string, int

PHP 7.1 – 7.4 (1 error)

Line Error
6 `Parameter #1 $str of function strtolower expects string, int

@phpstan-bot
Copy link
Contributor

@gnutix After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-7: Parameter #1 $str of function strtolower expects string, int|string given.
+PHP 8.0 (1 error)
+==========
+
+7: Parameter #1 $string of function strtolower expects string, int given.
+
+PHP 7.1 – 7.4 (1 error)
+==========
+
+7: Parameter #1 $str of function strtolower expects string, int given.
Full report

PHP 8.0 (1 error)

Line Error
7 Parameter #1 $string of function strtolower expects string, int given.

PHP 7.1 – 7.4 (1 error)

Line Error
7 Parameter #1 $str of function strtolower expects string, int given.

@phpstan-bot
Copy link
Contributor

@gnutix After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-6: Parameter #1 $str of function strtolower expects string, int|string given.
+No errors

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src#481

@github-actions
Copy link

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 Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants