Skip to content

preg_replace_callback doesn't account for flags in callback signature #10396

@Riimu

Description

@Riimu

Bug report

PHP 7.4 added support for flags to preg_replace_callback() and preg_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 if PREG_OFFSET_CAPTURE or PREG_UNMATCHED_AS_NULL flags are used

Code 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions