[php 8.1] preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated
Feature Request
There's an unhandled PHP 8.1 deprecation scenario with preg_split that's currently not handled.
Example https://3v4l.org/cVPim
I guess we need something similar to NullToStrictStringFuncCallArgRector but for integers.
Diff
Proposed change should be to convert the NULL to a -1.
$output = "a b\n\nc";
-var_dump(preg_split('/\s/', $output, NULL, PREG_SPLIT_NO_EMPTY));
+var_dump(preg_split('/\s/', $output, -1, PREG_SPLIT_NO_EMPTY));
$limit = null;
-var_dump(preg_split('/\s/', $output, $limit, PREG_SPLIT_NO_EMPTY));
+var_dump(preg_split('/\s/', $output, (int) $limit, PREG_SPLIT_NO_EMPTY));
what the different between pass -1 and 0?
using cast (int) NULL result 0 if we are going to using cast for similar transform
Reading documentation, it seems pass 0 or -1 is equal:
limit
----
If specified, then only substrings up to limit are returned with the rest of the string being placed in the last substring. A limit of -1 or 0 means "no limit".
so, it seems similar logic can be used for the new rule to use cast int for defined functions.
could you create PR? Thank you
@samsonasik Could you add a rule for this one as well? 👍 Should be part of PHP 8.1 set
I will try
I created PR:
- https://github.com/rectorphp/rector-src/pull/7240
for it.