-
Notifications
You must be signed in to change notification settings - Fork 482
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
Remove null-return on preg_replace() with valid patterns #3338
Conversation
20f79f5
to
e434231
Compare
//cc @thg2k |
e6474b4
to
4472f32
Compare
See the original issue. I was proven wrong: a perfectly valid regexp can still fail based on the input. So maybe if the regexp looks correct we return a benevolent union with null? |
This pull request has been marked as ready for review. |
failing build in phpdoc-parser repo is related to a baselined error which no longer happens after the PR (because benevolent) |
@@ -18,7 +18,7 @@ public function replace(string $search, string $replacement, string $subject){ | |||
assertType('non-empty-string', str_replace($search, $replacement, $subject)); | |||
assertType('non-empty-string', str_ireplace($search, $replacement, $subject)); | |||
|
|||
assertType('non-empty-string|null', preg_replace($search, $replacement, $subject)); | |||
assertType('(non-empty-string|null)', preg_replace($search, $replacement, $subject)); | |||
|
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.
Seems a preexisting problem, but it's wrong: preg_replace('/^a(b?)/', '\\1', 'a');
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.
Please open a new issue
Do we want this? Why it would be benevolent? Do we not want the user to always check for errors? |
I think it was one of the requests of the initial issue. dropped benevolence now and reduced it to the bugfix only |
Thank you! |
Remove null-return on preg_replace() with valid patternsReturn benevolent union from preg_replace()closes phpstan/phpstan#11547
requires #3339