Skip to content

Fix function signatures for preg_replace_callback[_array] for PHP 7.4+#411

Merged
ondrejmirtes merged 1 commit intophpstan:masterfrom
jabrandes:fix/signature@preg_replace_callback
Dec 21, 2020
Merged

Fix function signatures for preg_replace_callback[_array] for PHP 7.4+#411
ondrejmirtes merged 1 commit intophpstan:masterfrom
jabrandes:fix/signature@preg_replace_callback

Conversation

@jabrandes
Copy link
Copy Markdown
Contributor

Current function signatures for preg_replace_callback and preg_replace_callback_array do not include the $flags argument introduced in PHP 7.4 (see https://www.php.net/manual/en/function.preg-replace-callback.php and https://www.php.net/manual/en/function.preg-replace-callback-array.php). This pull request should (hopefully) fix that.

@ondrejmirtes
Copy link
Copy Markdown
Member

Hi, can you show me a false positive on phpstan.org, so we can verify this fix? Thank you.

@jabrandes
Copy link
Copy Markdown
Contributor Author

Hi @ondrejmirtes. This code should do for an example:

<?php declare(strict_types = 1);

class HelloWorld
{
    public function somePregReplaceCallbackExample(): ?string
    {
        return \preg_replace_callback(
            '#example(\w+)?#',
            fn ($matches) => $matches[1] ? ': $1' : '',
            'example',
            -1,
            $count,
            \PREG_UNMATCHED_AS_NULL,
        );
    }
}

Result on the PHPStan Playground:

image

@ondrejmirtes
Copy link
Copy Markdown
Member

Hi, the playground has Share button. Please post the link to it. Thanks.

@jabrandes
Copy link
Copy Markdown
Contributor Author

jabrandes commented Dec 21, 2020

@ondrejmirtes ondrejmirtes merged commit 432b3d6 into phpstan:master Dec 21, 2020
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants