Skip to content
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 - trailling groups are not optional when PREG_UNMATCHED_AS_NULL #3219

Merged
merged 6 commits into from
Jul 10, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 10, 2024

@staabm staabm changed the base branch from 1.12.x to 1.11.x July 10, 2024 09:48
@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 1.12.x. If your code is relevant on 1.11.x and you want it to be released sooner, please rebase your pull request and change its target to 1.11.x.

@@ -116,13 +116,6 @@ function doOffsetCapture(string $s): void {
assertType('array{}|array{array{string, int<0, max>}, array{string, int<0, max>}, array{string, int<0, max>}, array{string, int<0, max>}}', $matches);
}

function doUnmatchedAsNull(string $s): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pre-existing test no longer has the same expectations across all php versions.
therefore I moved it into the bug-11311 tests and adjusted expectations accordingly

function doFoo(string $s) {
if (1 === preg_match('/(?<major>\d+)\.(?<minor>\d+)(?:\.(?<patch>\d+))?/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {

assertType('array{0: string, major: string, 1: string, minor: string, 2: string, patch: string|null, 3: string|null}', $matches);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another fix this PR provides: a non-optional group cannot be null even when PREG_UNMATCHED_AS_NULL is given

@staabm staabm marked this pull request as ready for review July 10, 2024 10:17
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit 66a7578 into phpstan:1.11.x Jul 10, 2024
451 of 454 checks passed
@ondrejmirtes
Copy link
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.

preg_match and PREG_UNMATCHED_AS_NULL with trailing optional sub-patterns
3 participants