Bug #73948 [Ana]: Preg_match_all should return NULLs on trailing optional capture groups.

From: Date: Sat, 14 Apr 2018 14:42:48 +0000
Subject: Bug #73948 [Ana]: Preg_match_all should return NULLs on trailing optional capture groups.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214746@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73948&edit=1

 ID:                 73948
 Updated by:         cmb@php.net
 Reported by:        tomasyorke at hotmail dot com
 Summary:            Preg_match_all should return NULLs on trailing
                     optional capture groups.
 Status:             Analyzed
 Type:               Bug
 Package:            PCRE related
 Operating System:   Windows 7
 PHP Version:        7.0.14
 Block user comment: N
 Private report:     N

 New Comment:

Since we now have PREG_UNMATCHED_AS_NULL, the solution appears to
be straight forward: fill up NULL values at the end, only if
PREG_UNMATCHED_AS_NULL is used.  Since this option is only
available as of PHP 7.2.0, the resulting BC break seems to be
acceptable.


Previous Comments:
------------------------------------------------------------------------
[2018-04-14 14:39:07] cmb@php.net

Related To: Bug #76221

------------------------------------------------------------------------
[2017-01-23 18:31:19] cmb@php.net

> But why would you need an RFC for a bugfix?

An RFC might be over the top, but at least a PR to get some
attention appears to be appropriate.

------------------------------------------------------------------------
[2017-01-23 17:53:31] tomasyorke at hotmail dot com

If you wish to delay this change until 7.2, that sounds fine.
But why would you need an RFC for a bugfix?

------------------------------------------------------------------------
[2017-01-23 17:43:39] tomasyorke at hotmail dot com

I'm glad we didn't go the unset route. Having fixed sized arrays is useful for looping by
groups/matches independently of the Flag used.
You also can very easily know how many groups/matches the regex returned/contained.
By making the output array dynamicly sized. You only allow for an easy way to determine one of these
things. While making the other more complex.

------------------------------------------------------------------------
[2017-01-23 17:17:20] cmb@php.net

Regarding the BC break: when fixing <https://bugs.php.net/61780> I
would have preferred to unset unmatched captures, but that
appeared too much of a BC break (consider somebody is count()ing
the $matches). Therefore I changed the empty strings to NULL.

Adding unmatched trailing captures as NULL would still have the
same BC concerns – I don't think we can do that before PHP 7.2,
and even that might require the RFC process.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=73948


--
Edit this bug report at https://bugs.php.net/bug.php?id=73948&edit=1


Thread (19 messages)

« previous php.bugs (#214746) next »