php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60320 inaccuracy in array_slice documentation for length parameter
Submitted: 2011-11-17 16:07 UTC Modified: 2011-11-17 16:29 UTC
From: alastair at propcom dot co dot uk Assigned: rquadling (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: all
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: alastair at propcom dot co dot uk
New email:
PHP Version: OS:

 

 [2011-11-17 16:07 UTC] alastair at propcom dot co dot uk
Description:
------------
The description of the 'length' parameter says "If length is given and is 
positive, then the sequence will have that many elements in it.". This is only 
true if there are that many elements. If the array is shorter than that, the 
sequence will not be forcibly extended; instead it will have as many elements as 
could be extracted from the array.

Test script:
---------------
var_dump( array_slice( array(1, 2, 3), 0, 5 ) );


Expected result:
----------------
array (
  0 => 1,
  1 => 2,
  2 => 3,
  3 => null,
  4 => null,
)

Actual result:
--------------
array (
  0 => 1,
  1 => 2,
  2 => 3,
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-17 16:29 UTC] rquadling@php.net
Automatic comment from SVN on behalf of rquadling
Revision: http://svn.php.net/viewvc/?view=revision&revision=319411
Log: A short array alters length description.
Fixes bug #60320
 [2011-11-17 16:29 UTC] rquadling@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: rquadling
 [2011-11-17 16:29 UTC] rquadling@php.net
This bug has been fixed in SVN.

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/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 00:00:01 2026 UTC