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
 [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: Thu Oct 08 09:00:02 2026 UTC