ID: 50887
Updated by: [email protected]
Reported By: harrrrpo at gmail dot com
-Status: Open
+Status: Wont fix
Bug Type: PCRE related
Operating System: Windows
PHP Version: 5.3.1
New Comment:
I don't think we can change that behaviour at this point for the sake
of not brekaing BC.
Previous Comments:
------------------------------------------------------------------------
[2010-01-30 16:58:58] harrrrpo at gmail dot com
Description:
------------
in preg_match , when optional sub-patterns (using ? or {0,n} ) are the
last sub-patterns and empty (e.g. not matched) they are ignored in
$matches array
this behavior is inconsistent with preg_match_all , and with the case
when the empty optional sub-pattern isn't the last one
Reproduce code:
---------------
$str="1";
preg_match("#\d(\d)?#",$str,$mt);
var_dump($mt);
Expected result:
----------------
array(2) {
[0]=>
string(1) "1"
[1]=>
string(0) ""
}
(the string(0) "" does appear on all cases with preg_match_all , and
with preg_match , when there is any additional sub-patterns after it)
Actual result:
--------------
array(1) {
[0]=>
string(1) "1"
}
(the value of sub-pattern vanished)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50887&edit=1