-
Notifications
You must be signed in to change notification settings - Fork 473
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
Allow overriding the PHP 7.2 support for PREG_UNMATCHED_AS_NULL #3226
Conversation
I agree having impl specific feature toggles in phpstan-src looks fishy - especially for such an ancient php version. lets see what ondrey thinks about it |
Yeah, I guess alternatively I could simply copy the code in composer/pcre 2.x, it's not that much and shouldn't change too often once stabilized Edit: that might allow me to remove the conflict on older phpstan too I guess as a bonus.. |
the lets wait for ondrej. he usually has a clear opinion on such things ;) |
please don't adjust the PR until ondrej gave some insight though. |
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.
I'm mostly in favour of this, but what about a custom flag that would be a public constant in RegexArrayShapeMatcher and that would be passed into int $flags
? We just need to make sure we're not conflicting with existing PCRE flags.
Yeah that's a great idea to avoid polluting the arg list, I'll investigate. |
Ok I think that's what you meant? |
the phpdoc type needs a fix:
|
/** | ||
* Pass this into $flagsType as well if the library supports emulating PREG_UNMATCHED_AS_NULL on PHP 7.2 and 7.3 | ||
*/ | ||
public const PREG_UNMATCHED_AS_NULL_ON_72_73 = 2048; |
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.
The highest in use currently is 256, so I chose 2048 to leave 512/1024 as gaps if PHP should add new constants there.
/** @var int-mask<PREG_OFFSET_CAPTURE | PREG_UNMATCHED_AS_NULL | self::PREG_UNMATCHED_AS_NULL_ON_72_73> $flags */ | ||
$flags = $flagsType->getValue() & (PREG_OFFSET_CAPTURE | PREG_UNMATCHED_AS_NULL | self::PREG_UNMATCHED_AS_NULL_ON_72_73); |
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.
Somehow phpstan thinks it's an int<0, 2816>
as that's the value on the right. Could be nice if it was smarter here but I guess bitwise use is rare enough that it's not worth that much time spent optimizing for them.
The var annotation fixed it though.
Thank you! |
Cool, implemented in composer/pcre@088f752 and it works great! |
cc @staabm
I am not sure if this is too ugly or too specific for you to care, but in composer/pcre I did build a compat layer for PREG_UNMATCHED_AS_NULL on PHP 7.2/7.3 - so it would be nice if I could enable this flag to get proper return types even on PHP 7.2/7.3
If it's too ugly I understand, and I'll live with it until Composer can drop 7.2 :)