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

Distinguish between unmatched subpatterns and empty matches in preg_*() #1303

Merged
merged 4 commits into from Jan 6, 2017

Conversation

cmb69
Copy link
Contributor

@cmb69 cmb69 commented May 23, 2015

Currently it is not easily possible to distinguish between unmatched subpatterns (i.e. unset substrings) and empty matches in preg_match(_all); in both cases an empty string is yielded. Using PREG_OFFSET_CAPTURE makes that possible (negative offset indicate unmatched subpatterns), but that seems to be unnecessarily clumsy.

In bug #61780 it has been proposed not to set the respective keys in $matches, but that might be too big a BC break even for PHP 7.0.0. Setting those to NULL, however, might be acceptable, and would still allow to distinguish between the two cases (even with isset). Therefore I think this PR would resolve bug #61780.

@smalyshev
Copy link
Contributor

I think this makes sense.

@php-pulls php-pulls merged commit 5ca664a into php:master Jan 6, 2017
php-pulls pushed a commit that referenced this pull request Jan 6, 2017
* pull-request/1303:
  Distinguish between unmatched subpatterns and empty matches in preg_*()
  news entry for PR #1303
@krakjoe
Copy link
Member

krakjoe commented Jan 6, 2017

Thanks :)

@nikic
Copy link
Member

nikic commented Jan 6, 2017

This needs a note in UPGRADING, as it's BC breaking.

@cmb69
Copy link
Contributor Author

cmb69 commented Jan 6, 2017

This needs a note in UPGRADING, as it's BC breaking.

Done with commit c832ab4.

@krakjoe
Copy link
Member

krakjoe commented Jan 6, 2017

@nikic sorry, forgot about upgrading ...

@cmb69 thanks for picking up the slack ;)

@cmb69 cmb69 deleted the pcre-unset branch January 6, 2017 10:58
gsherwood added a commit to squizlabs/PHP_CodeSniffer that referenced this pull request Jan 11, 2017
photodude added a commit to photodude/coding-standards that referenced this pull request Feb 20, 2017
wilsonge added a commit to joomla/coding-standards that referenced this pull request Feb 20, 2017
Fixed bug introduced by preg_match change from php/php-src#1303
photodude added a commit to photodude/coding-standards that referenced this pull request Mar 7, 2017
@nicolas-grekas
Copy link
Contributor

BC break, but why? Seriously, not again.

@ciaranmcnulty
Copy link

Documenting BC breaks is not enough - the policy is not to have them outside major versions.

Why not add a flag that controls this behaviour?

@Majkl578
Copy link
Contributor

Majkl578 commented Mar 23, 2017

Agreed, another useless BC break in minor version.

Please rather introduce something opt-in like PREG_SUBPATTERN_UNMATCHED_NULL (or whatever better) that could be turned on by default in next major version.

@hboomsma
Copy link

Is this behaviour going to stay? or will it change to something BC?

@Majkl578
Copy link
Contributor

This already breaks Symfony: symfony/symfony#22667

@nicolas-grekas
Copy link
Contributor

See #2526 to make this opt-in, removing the BC break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants