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

more precise preg_match types #11222

Closed
staabm opened this issue Jun 21, 2024 · 3 comments · Fixed by phpstan/phpstan-src#3369
Closed

more precise preg_match types #11222

staabm opened this issue Jun 21, 2024 · 3 comments · Fixed by phpstan/phpstan-src#3369

Comments

@staabm
Copy link
Contributor

staabm commented Jun 21, 2024

Feature request

while implementing the first iteration of preg_match array-shape inference, I got a few ideas on how the type inference could be improved.

leaving it here as a feature request, so its not forgotten

https://phpstan.org/r/1e3506dd-78dc-4bbe-9c9e-2a5a2928fcfc

Did PHPStan help you today? Did it make you happy in any way?

No response

@ondrejmirtes
Copy link
Member

First thing we should is to cover preg_match_all and maybe others as well.

@phpstan-bot
Copy link
Contributor

@staabm After the latest push in 1.12.x, PHPStan now reports different result with your code snippet:

@@ @@
-10: Expected type array{string, '£'|'€'}, actual: array<string>
-13: Expected type array{string, numeric-string}, actual: array<string>
-16: Expected type array{string, non-empty-string}, actual: array<string>
-19: Expected type array{string, non-empty-string}, actual: array<string>
-22: Expected type array{string, non-falsey-string}, actual: array<string>
+10: Expected type array{string, '£'|'€'}, actual: array{string, non-empty-string}
+22: Expected type array{string, non-falsey-string}, actual: array{string, non-empty-string}
Full report
Line Error
10 `Expected type array{string, '£'
22 Expected type array{string, non-falsey-string}, actual: array{string, non-empty-string}

@phpstan-bot
Copy link
Contributor

@staabm After the latest push in 1.12.x, PHPStan now reports different result with your code snippet:

@@ @@
-10: Expected type array{string, '£'|'€'}, actual: array<string>
-13: Expected type array{string, numeric-string}, actual: array<string>
-16: Expected type array{string, non-empty-string}, actual: array<string>
-19: Expected type array{string, non-empty-string}, actual: array<string>
-22: Expected type array{string, non-falsey-string}, actual: array<string>
+10: Expected type array{string, '£'|'€'}, actual: array{string, non-empty-string}
+22: Expected type array{string, non-falsey-string}, actual: array{string, non-falsy-string}
Full report
Line Error
10 `Expected type array{string, '£'
22 Expected type array{string, non-falsey-string}, actual: array{string, non-falsy-string}

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

Successfully merging a pull request may close this issue.

3 participants