php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43596 array_slice(): $length arg ignored when it is 0 (unlike in php5.2.5)
Submitted: 2007-12-14 14:52 UTC Modified: 2008-01-29 00:40 UTC
From: robin_fernandes at uk dot ibm dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.3CVS-2007-12-14 (snap) OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: robin_fernandes at uk dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-12-14 14:52 UTC] robin_fernandes at uk dot ibm dot com
Description:
------------
With php5.2.x, explicitly specifying an argument of length 0 would result in an array of length 0.
However, with the snaps for php5.3 and php6.0, the length argument is ignored if it is 0.

This may have been introduced by the patch for bug 43541, which fixed the type conversion for this parameter.

Note that testcase ext/standard/tests/array/array_slice.phpt is affected by this change.

Expected output below is taken from php5.2.5.

Reproduce code:
---------------
<?php
$a = array(1,2,3,4);
var_dump(array_slice($a, 1, 0));
?>

Expected result:
----------------
array(0) {
}

Actual result:
--------------
array(3) {
  [0]=>
  int(2)
  [1]=>
  int(3)
  [2]=>
  int(4)
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-14 14:54 UTC] robin_fernandes at uk dot ibm dot com
First line should read "With php5.2.x, explicitly specifying a $length argument of 0 would result in an array of length 0" - sorry.
 [2007-12-14 18:59 UTC] felipe@php.net
In PHP 5.3.0-dev (cli) (built: Dec 11 2007 13:57:26) returns:
array(0) {
}
 [2007-12-14 21:46 UTC] felipe@php.net
Seeing the code, we note that is intentional, and according to documentation: "If it is omitted, then the sequence will have everything from offset up until the end of the array."
Seems to be right.
 [2007-12-15 07:36 UTC] robin_fernandes at uk dot ibm dot com
Hi Felipe, thanks for the update.
I understand and agree with the documented case in which the argument is omitted. However, in the case described above, it is not omitted, but rather explicitly provided as 0.

If this change in behaviour is intentional, I think the documentation will need to be updated.
 [2008-01-25 20:16 UTC] msaraujo@php.net
I have tried with 5.2.5 and actual result is:
array(0) {
}

 [2008-01-26 17:45 UTC] robin_fernandes at uk dot ibm dot com
Hi msaraujo, thanks for looking at this. Just to ensure there is no confusion: the purpose of this report is to notify of a change in behaviour at least in the php 5.3 / 6.0 snaps. We agree that php 5.2.5 outputs array(0) { }, and I believe that is the correct output.
 [2008-01-29 00:40 UTC] tony2001@php.net
Fixed in CVS.
Please change the test accordingly.
It would be also really good if you divide that ENORMOUS test to a bunch of small (1000 linex max) tests.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 11 08:01:31 2024 UTC