Skip to content

[php 8.1] preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated #9160

Open
@codebymikey

Description

@codebymikey

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));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions