php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62804 array_slice(): Undocumented huge difference in behavior of across 5.2.4
Submitted: 2012-08-12 20:06 UTC Modified: 2013-10-23 08:10 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: matteosistisette at gmail dot com Assigned: krakjoe (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2012-08-12 20:06 UTC] matteosistisette at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.array-slice#refsect1-
function.array-slice-description
---

array array_slice ( array $array , int $offset [, int $length = NULL [, bool 
$preserve_keys = false ]] )

That the default value of the $length parameter is NULL is true only for php 
>=5.2.4

Prior to that version, passing NULL is NOT the same as omitting it.

Check this: http://3v4l.org/gW4pG
Note the difference in output between 5.2.3 and 5.2.4

Only starting from 5.2.4 it is as documented.

This has a TREMENDOUS impact and must be documented with a gigantic red warning.
Instead, it is not even mentioned.


The sentence "If it is omitted, then the sequence will have everything from 
offset up until the end of the array." _is_ correct for all version, but if one 
needs to specify the $preserve_keys parameter without specifying $length, one 
needs to pass the default value (that's why it's very relevant), and the value 
has changed.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-12 17:44 UTC] alvaro at demogracia dot com
Possible workaround:

<?php
$foo = array_slice($bar, 1, count($bar)-1, TRUE);
?>
 [2013-10-23 08:10 UTC] krakjoe@php.net
Automatic comment from SVN on behalf of krakjoe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=331920
Log: #62804 add information about parameter change in changelog
 [2013-10-23 08:10 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2013-10-23 08:10 UTC] krakjoe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

A note has been added to the changelog.

Thanks for your input.
 [2013-10-23 08:37 UTC] krakjoe@php.net
Automatic comment from SVN on behalf of krakjoe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=331923
Log: some precision for peter, #62804
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 00:01:32 2024 UTC