Bug #73948 [NEW]: Preg_match_all should return empty strings on optional capture groups.
From: tomasyorke at hotmail dot com
Operating system: Windows 7
PHP version: 7.0.14
Package: *Regular Expressions
Bug Type: Bug
Bug description:Preg_match_all should return empty strings on optional capture groups.
Description:
------------
Using preg_match_all with the PREG_SET_ORDER flag and an optional
capture group might return either an empty string or a missing element.
This depends on whether there is a matched capture group after the
non-matched capture group.
From an interface perspective, this means that I have to check for two
representations to test whether an optional capture group was matched.
The test script demonstrates such a case.
When considering a fix, the first priority should be that whatever the
representation is (NULL, an empty string or a missing element.), it
should be consistent, no matter if there is a matched capture group
after or not.
If this cannot be fixed due to backwards compatibility Issues. Could we
add a PREG_KEEP_NONMATCHES or PREG_SET_ORDER_2 flag?
Test script:
---------------
<?php
preg_match_all("#(a)?(b)(c)?#","b",$matches,PREG_SET_ORDER);
var_dump($matches);
Expected result:
----------------
array(1) {
[0] => array(3) {
[0] => string(1) "b" [1] => string(0) "" [2] => string(1)
"b" [3] =>
string(0) ""
}
}
Actual result:
--------------
array(1) {
[0] => array(3) {
[0] => string(1) "b" [1] => string(0) "" [2] => string(1)
"b"
}
}
--
Edit bug report at https://bugs.php.net/bug.php?id=73948&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73948&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73948&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73948&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73948&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73948&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73948&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73948&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73948&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73948&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73948&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73948&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73948&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73948&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73948&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73948&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73948&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73948&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73948&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73948&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73948&r=mysqlcfg
Thread (19 messages)
- tomasyorke at hotmail dot com
- requinix@php.netBug #73948 [Opn->Dup]: Preg_match_all should return empty strings on optional capture groups.
- nikic@php.netBug #73948 [Dup]: Preg_match_all should return empty strings on optional capture groups.
- requinix@php.netBug #73948 [Dup->Fbk]: Preg_match_all should return empty strings on optional capture groups.
- requinix@php.netBug #73948 [Fbk->Opn]: Preg_match_all should return NULLs on trailing optional capture groups.
- cmb@php.netBug #73948 [Opn->Ana]: Preg_match_all should return NULLs on trailing optional capture groups.
- tomasyorke at hotmail dot comBug #73948 [Com]: Preg_match_all should return NULLs on trailing optional capture groups.
- tomasyorke at hotmail dot comBug #73948 [Com]: Preg_match_all should return NULLs on trailing optional capture groups.
- cmb@php.netBug #73948 [Ana]: Preg_match_all should return NULLs on trailing optional capture groups.
- tomasyorke at hotmail dot comBug #73948 [Com]: Preg_match_all should return NULLs on trailing optional capture groups.
- tomasyorke at hotmail dot comBug #73948 [Com]: Preg_match_all should return NULLs on trailing optional capture groups.
- cmb@php.netBug #73948 [Ana]: Preg_match_all should return NULLs on trailing optional capture groups.
- cmb@php.netBug #73948 [Ana]: Preg_match_all should return NULLs on trailing optional capture groups.
- requinix@php.netBug #73948 [Ana]: Preg_match_all should return NULLs on trailing optional capture groups.
- nikic@php.netBug #73948 [Ana]: Preg_match_all should return NULLs on trailing optional capture groups.
- php at tecnopolis dot caBug #73948 [Com]: Preg_match_all should return NULLs on trailing optional capture groups.
- nikic@php.netBug #73948 [Ana->Asn]: Preg_match_all should return NULLs on trailing optional capture groups.
- nikic@php.netBug #73948 [Asn]: Preg_match_all should return NULLs on trailing optional capture groups.
- nikic@php.netBug #73948 [Asn->Csd]: Preg_match_all should return NULLs on trailing optional capture groups.