-
-
Notifications
You must be signed in to change notification settings - Fork 884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
preg_replace_callback doesn't account for flags in callback signature #10396
Labels
Milestone
Comments
@Riimu After the latest push in 2.0.x, PHPStan now reports different result with your code snippet: @@ @@
5: First-class callables are supported only on PHP 8.1 and later.
5: Parameter #2 $callback of function preg_replace_callback expects callable(array<int|string, string>): string, Closure(array<int|string, array{string|null, int}>): string given.
-PHP 7.4 (3 errors)
+PHP 7.4 (6 errors)
==========
+3: Function test() has invalid return type null.
+3: Function test() never returns null so it can be removed from the return type.
3: Function test() uses native union types but they're supported only on PHP 8.0 and later.
5: First-class callables are supported only on PHP 8.1 and later.
+5: Function test() should return null|string but returns string|null.
5: Parameter #2 $callback of function preg_replace_callback expects callable(array<int|string, string>): string, Closure(array<int|string, array{string|null, int}>): string given.
-PHP 7.2 – 7.3 (4 errors)
+PHP 7.2 – 7.3 (7 errors)
==========
+3: Function test() has invalid return type null.
+3: Function test() never returns null so it can be removed from the return type.
3: Function test() uses native union types but they're supported only on PHP 8.0 and later.
5: First-class callables are supported only on PHP 8.1 and later.
5: Function preg_replace_callback invoked with 6 parameters, 3-5 required.
+5: Function test() should return null|string but returns string|null.
5: Parameter #2 $callback of function preg_replace_callback expects callable(array<int|string, string>): string, Closure(array<int|string, array{string|null, int}>): string given. Full reportPHP 8.1 – 8.3 (1 error)
PHP 8.0 (2 errors)
PHP 7.4 (6 errors)
PHP 7.2 – 7.3 (7 errors)
|
@Riimu After the latest push in 2.0.x, PHPStan now reports different result with your code snippet: @@ @@
PHP 8.1 – 8.3 (1 error)
==========
-5: Parameter #2 $callback of function preg_replace_callback expects callable(array<int|string, string>): string, Closure(array<int|string, array{string|null, int}>): string given.
+5: Parameter #2 $callback of function preg_replace_callback expects callable(array<string>): string, Closure(array<int|string, array{string|null, int}>): string given.
PHP 8.0 (2 errors)
==========
5: First-class callables are supported only on PHP 8.1 and later.
-5: Parameter #2 $callback of function preg_replace_callback expects callable(array<int|string, string>): string, Closure(array<int|string, array{string|null, int}>): string given.
+5: Parameter #2 $callback of function preg_replace_callback expects callable(array<string>): string, Closure(array<int|string, array{string|null, int}>): string given.
-PHP 7.4 (3 errors)
+PHP 7.4 (6 errors)
==========
+3: Function test() has invalid return type null.
+3: Function test() never returns null so it can be removed from the return type.
3: Function test() uses native union types but they're supported only on PHP 8.0 and later.
5: First-class callables are supported only on PHP 8.1 and later.
-5: Parameter #2 $callback of function preg_replace_callback expects callable(array<int|string, string>): string, Closure(array<int|string, array{string|null, int}>): string given.
+5: Function test() should return null|string but returns string|null.
+5: Parameter #2 $callback of function preg_replace_callback expects callable(array<string>): string, Closure(array<int|string, array{string|null, int}>): string given.
-PHP 7.2 – 7.3 (4 errors)
+PHP 7.2 – 7.3 (7 errors)
==========
+3: Function test() has invalid return type null.
+3: Function test() never returns null so it can be removed from the return type.
3: Function test() uses native union types but they're supported only on PHP 8.0 and later.
5: First-class callables are supported only on PHP 8.1 and later.
5: Function preg_replace_callback invoked with 6 parameters, 3-5 required.
-5: Parameter #2 $callback of function preg_replace_callback expects callable(array<int|string, string>): string, Closure(array<int|string, array{string|null, int}>): string given.
+5: Function test() should return null|string but returns string|null.
+5: Parameter #2 $callback of function preg_replace_callback expects callable(array<string>): string, Closure(array<int|string, array{string|null, int}>): string given. Full reportPHP 8.1 – 8.3 (1 error)
PHP 8.0 (2 errors)
PHP 7.4 (6 errors)
PHP 7.2 – 7.3 (7 errors)
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
PHP 7.4 added support for flags to
preg_replace_callback()
andpreg_replace_callback_array()
. It seems, however, that PHPStan doesn't account for the$flags
parameter when determining the signature of the callback.Currently, PHPStan expects the callback signature to be
callable(array<int|string, string>): string
, which is not true ifPREG_OFFSET_CAPTURE
orPREG_UNMATCHED_AS_NULL
flags are usedCode snippet that reproduces the problem
https://phpstan.org/r/9b24636c-c960-45c8-9ef7-5ee47f34623f
Expected output
There should be no errors
Did PHPStan help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: