`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, '+'}|nullUsing version 1.3.6
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.
The fix was not yet released. Do you compare stable release and latest dev?
And I dont understand why the PHPStan results of Strings::match and preg_match differ.
Compare
And
https://github.com/phpstan/phpstan-src/blob/1.12.x/src/Type/Php/PregMatchTypeSpecifyingExtension.php
Note its by-ref arg handling vs. Dynamic return type and Strings::match can return null
I compare:
phpstan/phpstan-nette 1.3.6(gives array shape)phpstan/phpstan 1.11.10(gives generic array)
Oh I did not notice this diff. I need to look into details when back on a computer
in your example code the arguments are in wrong order
Oh god, this typo again. Thx & Sry
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.