#50887 [NEW]: preg_match , last optional sub-patterns ignored when empy
From: harrrrpo at gmail dot com
Operating system: Windows
PHP version: 5.3.1
PHP Bug Type: PCRE related
Bug description: preg_match , last optional sub-patterns ignored when empy
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 bug report at http://bugs.php.net/?id=50887&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50887&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50887&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50887&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=50887&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50887&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=50887&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=50887&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=50887&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=50887&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=50887&r=support
Expected behavior: http://bugs.php.net/fix.php?id=50887&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=50887&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=50887&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=50887&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50887&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50887&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=50887&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=50887&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=50887&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=50887&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=50887&r=mysqlcfg
Thread (9 messages)
- harrrrpo at gmail dot com
- nlopess@php.net#50887 [Opn->WFx]: preg_match , last optional sub-patterns ignored when empy
- cappuccino dot e dot cornetto at gmail dot comBug #50887 [Com]: preg_match , last optional sub-patterns ignored when empy
- arveen dot ponniah at loginbn dot chBug #50887 [Com]: preg_match , last optional sub-patterns ignored when empy
- c dot clix at tiscali dot itBug #50887 [Com]: preg_match , last optional sub-patterns ignored when empy
- cappuccino dot e dot cornetto at gmail dot comBug #50887 [Com]: preg_match , last optional sub-patterns ignored when empy
- c639615 at trbvn dot comBug #50887 [Com]: preg_match , last optional sub-patterns ignored when empy
- jflambert at newtrax dot comBug #50887 [Com]: preg_match , last optional sub-patterns ignored when empy
- nikic@php.netBug #50887 [Wfx]: preg_match , last optional sub-patterns ignored when empy