From: RQuadling at GoogleMail dot com Operating system: Windows XP SP3 PHP version: 5.3CVS-2009-06-26 (CVS) PHP Bug Type: PCRE related Bug description: preg_split with limit issues similar to old explode limit issues.
Description: ------------ This comes from the recent opened doc bug (http://bugs.php.net/bug.php? id=48703) and fixed bug http://bugs.php.net/bug.php?id=47560. In #48703, the OP says that the limit on preg_split() should be documented the same as the limit in explode (split). But the following code shows that the output is different in certain circumstances. For #48703 to be closed with the documentation being updated to match that of explode, then preg_split() needs to be amended to match the behaviour of explode with regards to the limit parameter. Reproduce code: --------------- <?php $string = 'one.two.three.four'; foreach(array('Valid' => '.', 'Invalid' => '_') as $valid => $delimiter) { $results[$valid]['No Limit'] = explode($delimiter, $string); foreach(range(-4, 4) as $limit) { $explode = explode($delimiter, $string, $limit); $preg_split = preg_split("`\\{$delimiter}`", $string, $limit); if (serialize($explode) !== serialize($preg_split)) { echo "BAD : Output does not match for a delimiter of '$delimiter' ($valid) and a limit of $limit.", PHP_EOL, 'EXPLODE : ', implode(' : ', $explode), PHP_EOL, 'PREG_SPLIT : ', implode(' : ', $preg_split), PHP_EOL, PHP_EOL; } else { echo "GOOD : Output does match for a delimiter of '$delimiter' ($valid) and a limit of $limit.", PHP_EOL, PHP_EOL; } } } Expected result: ---------------- GOOD : Output does not match for a delimiter of '.' (Valid) and a limit of -4. GOOD : Output does not match for a delimiter of '.' (Valid) and a limit of -3. GOOD : Output does not match for a delimiter of '.' (Valid) and a limit of -2. GOOD : Output does not match for a delimiter of '.' (Valid) and a limit of -1. GOOD : Output does not match for a delimiter of '.' (Valid) and a limit of 0. GOOD : Output does not match for a delimiter of '.' (Valid) and a limit of 1. GOOD : Output does not match for a delimiter of '.' (Valid) and a limit of 2. GOOD : Output does not match for a delimiter of '.' (Valid) and a limit of 3. GOOD : Output does not match for a delimiter of '.' (Valid) and a limit of 4. GOOD : Output does not match for a delimiter of '_' (Invalid) and a limit of -4. GOOD : Output does not match for a delimiter of '_' (Invalid) and a limit of -3. GOOD : Output does not match for a delimiter of '_' (Invalid) and a limit of -2. GOOD : Output does not match for a delimiter of '_' (Invalid) and a limit of -1. GOOD : Output does not match for a delimiter of '_' (Invalid) and a limit of 0. GOOD : Output does not match for a delimiter of '_' (Invalid) and a limit of 1. GOOD : Output does not match for a delimiter of '_' (Invalid) and a limit of 2. GOOD : Output does not match for a delimiter of '_' (Invalid) and a limit of 3. GOOD : Output does not match for a delimiter of '_' (Invalid) and a limit of 4. Actual result: -------------- BAD : Output does not match for a delimiter of '.' (Valid) and a limit of -4. EXPLODE : PREG_SPLIT : one.two.three.four BAD : Output does not match for a delimiter of '.' (Valid) and a limit of -3. EXPLODE : one PREG_SPLIT : one.two.three.four BAD : Output does not match for a delimiter of '.' (Valid) and a limit of -2. EXPLODE : one : two PREG_SPLIT : one.two.three.four BAD : Output does not match for a delimiter of '.' (Valid) and a limit of -1. EXPLODE : one : two : three PREG_SPLIT : one : two : three : four BAD : Output does not match for a delimiter of '.' (Valid) and a limit of 0. EXPLODE : one.two.three.four PREG_SPLIT : one : two : three : four GOOD : Output does match for a delimiter of '.' (Valid) and a limit of 1. GOOD : Output does match for a delimiter of '.' (Valid) and a limit of 2. GOOD : Output does match for a delimiter of '.' (Valid) and a limit of 3. GOOD : Output does match for a delimiter of '.' (Valid) and a limit of 4. BAD : Output does not match for a delimiter of '_' (Invalid) and a limit of -4. EXPLODE : PREG_SPLIT : one.two.three.four BAD : Output does not match for a delimiter of '_' (Invalid) and a limit of -3. EXPLODE : PREG_SPLIT : one.two.three.four BAD : Output does not match for a delimiter of '_' (Invalid) and a limit of -2. EXPLODE : PREG_SPLIT : one.two.three.four BAD : Output does not match for a delimiter of '_' (Invalid) and a limit of -1. EXPLODE : PREG_SPLIT : one.two.three.four GOOD : Output does match for a delimiter of '_' (Invalid) and a limit of 0. GOOD : Output does match for a delimiter of '_' (Invalid) and a limit of 1. GOOD : Output does match for a delimiter of '_' (Invalid) and a limit of 2. GOOD : Output does match for a delimiter of '_' (Invalid) and a limit of 3. GOOD : Output does match for a delimiter of '_' (Invalid) and a limit of 4. -- Edit bug report at http://bugs.php.net/?id=48704&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48704&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48704&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48704&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=48704&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48704&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=48704&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=48704&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=48704&r=needscript Try newer version: http://bugs.php.net/fix.php?id=48704&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=48704&r=support Expected behavior: http://bugs.php.net/fix.php?id=48704&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=48704&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=48704&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=48704&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48704&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=48704&r=dst IIS Stability: http://bugs.php.net/fix.php?id=48704&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=48704&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=48704&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=48704&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=48704&r=mysqlcfg