Skip to content

RegexArrayShapeMatcher - Fix PREG_UNMATCHED_AS_NULL with top level alternation #3238

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

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 15, 2024

this PREG_UNMATCHED_AS_NULL thing really affects all kind of types :-)

@staabm staabm changed the base branch from 1.12.x to 1.11.x July 15, 2024 07: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.

@staabm
Copy link
Contributor Author

staabm commented Jul 15, 2024

//cc @Seldaek

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

This pull request has been marked as ready for review.

class UnmatchedAsNullWithTopLevelAlternation {
function doFoo(string $s): void {
if (preg_match('/Price: (?:(£)|(€))\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
assertType('array{string, string|null, string|null}', $matches); // could be array{0: string, 1: null, 2: string}|array{0: string, 1: string, 2: null}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that would be nicer for sure ;) But strictly speaking at least this is correct.

@ondrejmirtes ondrejmirtes merged commit b116e71 into phpstan:1.11.x Jul 15, 2024
454 of 457 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the reg-top branch July 15, 2024 11:51
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.

4 participants