ID:               48704
 Updated by:       j...@php.net
 Reported By:      RQuadling at GoogleMail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         PCRE related
 Operating System: Windows XP SP3
 PHP Version:      5.3CVS-2009-06-26 (CVS)
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php




Previous Comments:
------------------------------------------------------------------------

[2009-06-26 18:49:24] sjoerd-php at linuxonly dot nl

Thank you for your bug report.

The $limit parameter to explode() and preg_split() has different
meanings. They differ when $limit is negative. The behavior of $limit is
correctly documented and thus different for both functions.

Bug 48703 suggests than the preg_split() documentation gets improved to
describe that the last element of the array contains the remaining part
of the string. It does not suggest that the documentation for the limit
parameter is changed to be the same as that of explode().

Your example assumes that the $limit parameter behaves the same for
preg_split() and explode(), which is not the case. Thus, I don't think
your report describes a bug.

------------------------------------------------------------------------

[2009-06-26 14:24:38] rquadl...@php.net

Missed a small point. If no limit is supplied explode() and
preg_split() 
provide the same output (with a valid or invalid delimiter).

------------------------------------------------------------------------

[2009-06-26 14:20:48] RQuadling at GoogleMail dot com

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 this bug report at http://bugs.php.net/?id=48704&edit=1

Reply via email to