Skip to content

non-empty-string|array in str_replace #9870

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

Open
takaram opened this issue Sep 11, 2023 · 1 comment · May be fixed by phpstan/phpstan-src#4023
Open

non-empty-string|array in str_replace #9870

takaram opened this issue Sep 11, 2023 · 1 comment · May be fixed by phpstan/phpstan-src#4023
Labels
Milestone

Comments

@takaram
Copy link

takaram commented Sep 11, 2023

Feature request

Related to #5323

PHPStan knows str_replace returns non-empty-string when all three arguments are non-empty-string, but it's not true when subject is non-empty-string|array.

https://phpstan.org/r/ebe95b41-e0bf-4a1e-8eb3-3d3e4492555e

Line 13 should be list<non-empty-string>|non-empty-string

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

I appreciate your hard work to improve PHPStan!

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Sep 11, 2023
@phpstan-bot
Copy link
Contributor

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

@@ @@
 ==========
 
  9: Dumped type: non-empty-string
-11: Dumped type: array<int, string>
-13: Dumped type: array<int, string>|string
+11: Dumped type: array<int<0, max>, string>
+13: Dumped type: list<string>|string
 
 PHP 7.2 – 7.4 (4 errors)
 ==========
@@ @@
 
  6: Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
  9: Dumped type: non-empty-string
-11: Dumped type: array<int, string>
-13: Dumped type: array<int, string>|string
+11: Dumped type: array<int<0, max>, string>
+13: Dumped type: list<string>|string
Full report

PHP 8.0 – 8.3 (3 errors)

Line Error
9 Dumped type: non-empty-string
11 Dumped type: array<int<0, max>, string>
13 `Dumped type: list

PHP 7.2 – 7.4 (4 errors)

Line Error
6 Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
9 Dumped type: non-empty-string
11 Dumped type: array<int<0, max>, string>
13 `Dumped type: list

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

Successfully merging a pull request may close this issue.

3 participants