|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-06-07 16:52 UTC] cmb@php.net
-Status: Open
+Status: Duplicate
-Assigned To:
+Assigned To: cmb
[2016-06-07 16:52 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 13:00:01 2025 UTC |
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")