phpstan icon indicating copy to clipboard operation
phpstan copied to clipboard

str_replace after preg_match is always string but phpstan says array

Open JulianAtkins opened this issue 2 years ago • 0 comments

Bug report

I'm running two preg_match functions on strings and then pass the result to str_replace. PHPStan complains that my strings could be arrays.

Here is the result after running the code:

array(3) {
  [0]=>
  array(0) {
  }
  [1]=>
  string(6) "string"
  [2]=>
  string(6) "string"
}

As you can see, key 1 and key 2 are always strings.

Code snippet that reproduces the problem

https://phpstan.org/r/8b744f0a-bff9-4b52-8109-ae39e862a0f5

Expected output

I expected PHPStan to produce no errors.

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

PHPStan is the awesomest PHP tool in the world! no exaggeration :smile:

JulianAtkins avatar Jan 12 '24 15:01 JulianAtkins