-
Notifications
You must be signed in to change notification settings - Fork 471
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
RegexArrayShapeMatcher - (\d*)
can be empty-string
#3257
Conversation
//cc @Seldaek |
|
||
function (string $s): void { | ||
preg_match('/%a(\d*)?/', $s, $matches, PREG_UNMATCHED_AS_NULL); | ||
assertType("array{0?: string, 1?: ''|numeric-string|null}", $matches); // could be array{0?: string, 1?: ''|numeric-string} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! What's the matter here tho?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case php-src does not return NULL
for the unmatched group even if PREG_UNMATCHED_AS_NULL
.
that would be another special case we need to hardcode - therefore I went with leaving it less precise and have this unnecessary null
in here.
I have a feeling that the ArrayShapeMatcher will get enough special cases with preg_match_all
support ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ok, it should be ''|numeric-string
, or unset if outside the true-match-arm.
PREG_UNMATCHED_AS_NULL has no impact here because (\d*)
matches an empty string too, so it always matches. It's technically not optional despite the ?
that follows, as long as it is not wrapped in something that contains some content.. e.g. the third example here https://3v4l.org/92geX
So I guess one rule could be that if the inside of a match group resolves to MAYBE empty string, then the match group should never be nullable as long as its parents are also not nullable.
Thank you! |
No description provided.