php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47560 explode()'s limit parameter odd behaviour
Submitted: 2009-03-04 12:37 UTC Modified: 2009-04-01 17:22 UTC
From: RQuadling at GMail dot com Assigned: mattwil (profile)
Status: Closed Package: Strings related
PHP Version: 5.3CVS-2009-03-04 (snap) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: RQuadling at GMail dot com
New email:
PHP Version: OS:

 

 [2009-03-04 12:37 UTC] RQuadling at GMail dot com
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;
	}




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-05 01:26 UTC] felipe@php.net
Hi Kalle,
This issue looks like documentation problem. I guess that your commit to #47546 must be reverted.
 [2009-04-01 17:22 UTC] mattwil@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Yeah, change for Bug #47546 was reverted. It is a documentation problem. See Bug #47727.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 06 02:01:30 2024 UTC