From:             
Operating system: Win XP Pro
PHP version:      5.3.2
Package:          PCRE related
Bug Type:         Feature/Change Request
Bug description:preg_match: Capturing subpatterns that don't match get empty 
string.

Description:
------------
Capturing subpatterns that don't match anything still show an empty string
in the match array.



Since empty string is a legitimate value, the match array should have null
or false instead.



The workaround to detect a capturing subpattern not matching anything is to
use PREG_OFFSET_CAPTURE and look for offset -1 for the particular
subpattern.

Test script:
---------------
<?php



preg_match('%(a)|(b)%','b',$m);

var_dump($m);



//$m[1] === "" as if the first capturing parentheses matched ""

//$m[1] === null would be more appropriate (javascript uses "undefined")




-- 
Edit bug report at http://bugs.php.net/bug.php?id=51881&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51881&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51881&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=51881&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51881&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51881&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51881&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51881&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51881&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51881&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51881&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51881&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51881&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51881&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51881&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51881&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51881&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51881&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51881&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51881&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51881&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51881&r=mysqlcfg

Reply via email to