Skip to content

preg_match_all with PREG_SET_ORDER does not see capture group as optional #11661

@user16920

Description

@user16920

Bug report

The regex analyzer wrongly sees an optional capture group as always matching when it is followed by a required capture group

Code snippet that reproduces the problem

https://phpstan.org/r/8672bf06-a297-4186-bd3e-b0b21f3959e2

Expected output

I expect the resulting type to be array<int, array{string, ''|'ERR', non-empty-string}> as the first capturing group is optional. See https://3v4l.org/iaF0d for runtime results

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions