-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Labels
Description
Bug report
The latest version of PHPStan incorrectly believes that the explode() function returns an empty array in cases where it doesn't.
Per the PHP manual:
Returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter.
If delimiter is an empty string (""), explode() will return FALSE. If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned, otherwise an array containing string will be returned.
Code snippet that reproduces the problem
See https://phpstan.org/r/a664b522-b2d8-4541-a071-f1e768a0f9ad
This snippet will always return a non-empty array because (per the PHP documentation):
If delimiter is an empty string (""), explode() will return FALSE.The string is never going to be emptyIf delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returnedwe're not providing a negative limit - we're using the default ofPHP_INT_MAX- otherwise an array containing string will be returned - this is what the sample snippet always does
Expected output
PHPStan should not report any false errors
Reactions are currently unavailable