Doc #62804 [Com]: array_slice(): Undocumented huge difference in behavior of across 5.2.4
| From: | alvaro at demogracia dot com | Date: | Wed, 12 Dec 2012 17:44:28 +0000 |
| Subject: | Doc #62804 [Com]: array_slice(): Undocumented huge difference in behavior of across 5.2.4 | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9282@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62804&edit=1
ID: 62804
Comment by: alvaro at demogracia dot com
Reported by: matteosistisette at gmail dot com
Summary: array_slice(): Undocumented huge difference in
behavior of across 5.2.4
Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Possible workaround:
<?php
$foo = array_slice($bar, 1, count($bar)-1, TRUE);
?>
Previous Comments:
------------------------------------------------------------------------
[2012-08-12 20:06:33] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62804&edit=1