From: RQuadling at GMail dot com
Operating system: Windows XP SP3
PHP version: 5.3CVS-2009-03-04 (snap)
PHP Bug Type: Strings related
Bug description: explode()'s limit parameter odd behaviour
Description:
------------
With regard to #47546, the behaviour of no $limit supplied and $limit
supplied as the default now match, but the output is wrong.
I've run the following code for V5.2.8, V5.2.10-dev and V5.3.0beta2-
dev (the devs are the latest win32 snapshots).
Here is a summary ...
V5.2.8
No limit - 4 entries
Limit of -4 - No entries
Limit of -3 - 1 entry
Limit of -2 - 2 entries
Limit of -1 - 4 entries *** Should be 3 entries
Limit of 0 - 1 entry
Limit of 1 - 1 entry
Limit of 2 - 2 entries
Limit of 3 - 3 entries
Limit of 4 - 4 entries *** Matches No Limit
5.2.10-dev and 5.3.0beta2-dev
No limit - 4 entries
Limit of -4 - No entries
Limit of -3 - 1 entry
Limit of -2 - 2 entries
Limit of -1 - 4 entries *** Should be 3 entries but does match No
Limit
Limit of 0 - 1 entry
Limit of 1 - 1 entry
Limit of 2 - 2 entries
Limit of 3 - 3 entries
Limit of 4 - 4 entries *** Matches No Limit
It would seem that the idea of limit has a static value default is
inappropriate. If anything the default for limit is the number of
elements in no limiting takes place.
Also a limit of -1 should be returning 3 elements and not 4.
Richard.
Reproduce code:
---------------
<?php
$s_Imploded = 'one.two.three.four';
$s_Exploded = serialize(explode('.', $s_Imploded));
echo PHP_VERSION, PHP_EOL;
echo 'No limit supplied.', PHP_EOL, var_export(explode('.', $s_Imploded),
True), PHP_EOL;
for ($i_Limit = -4 ; $i_Limit <= 4 ; ++$i_Limit)
{
echo "Testing limit of $i_Limit", PHP_EOL, var_export(explode('.',
$s_Imploded, $i_Limit), True), PHP_EOL;
if (serialize(explode('.', $s_Imploded, $i_Limit)) === $s_Exploded)
{
echo "A limit of $i_Limit matches the output when no limit has
been
supplied.", PHP_EOL;
}
echo PHP_EOL;
}
--
Edit bug report at http://bugs.php.net/?id=47560&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47560&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47560&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47560&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47560&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47560&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47560&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47560&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47560&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47560&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47560&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47560&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47560&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47560&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47560&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47560&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47560&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47560&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47560&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47560&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47560&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47560&r=mysqlcfg