phpstan/phpstan-nette

`Strings::match($pattern, '#([+-])#')` wrongly results in `array{string, '+'}|null`

Closed this issue · 13 comments

Regular preg_match in PHPStan 1.11.10 does not suffer this issue:

preg_match($s, '#([+-])#', $nativeMatch);
$netteMatch = Strings::match($s, '#([+-])#');

\PHPStan\dumpType($nativeMatch); // array<string>
\PHPStan\dumpType($netteMatch); // array{string, '+'}|null

Using version 1.3.6

staabm commented

whats your expected result? is it the same bug as fixed recently on phpstan-src in phpstan/phpstan#11490 ?

Looks like exactly that, thx.


And I dont understand why the PHPStan results of Strings::match and preg_match differ.

staabm commented

The fix was not yet released. Do you compare stable release and latest dev?

I compare:

  • phpstan/phpstan-nette 1.3.6 (gives array shape)
  • phpstan/phpstan 1.11.10 (gives generic array)
staabm commented

Oh I did not notice this diff. I need to look into details when back on a computer

staabm commented

in your example code the arguments are in wrong order

https://phpstan.org/r/a77b2f6a-852b-497a-83d8-fa099fedba7c

Oh god, this typo again. Thx & Sry

staabm commented

so this issue can be closed?

The fix feels valid, but I'm not 100% sure it fixes it here. If you are, feel free to close it.

I can confirm this is fixed in latest versions.

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.