Skip to content

Casting preg_match() return value breaks array shapes for $matches by-ref parameter #11262

@westonruter

Description

@westonruter

Bug report

I just noticed that phpstan/phpstan-src#2589 doesn't seem to play well with strict rules.

This example without strict rules works: https://phpstan.org/r/6187bcca-8fc8-459b-9790-21a82e62b345

But when I enable strict rules, I need to cast the return value of preg_match() to a bool and this seems to block the types from passing through. For example: https://phpstan.org/r/f368fc07-6438-43f1-b80b-93dee22535f4

Same thing happens when I cast to an int: https://phpstan.org/r/0d011355-4446-4bd8-9b8d-0c44907f9a07

Code snippet that reproduces the problem

https://phpstan.org/r/f368fc07-6438-43f1-b80b-93dee22535f4

Expected output

No issue should have been detected

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