Doc #69735 [Opn]: array_splice() return value could be confusing
| From: | chealer at gmail dot com | Date: | Sun, 31 May 2015 19:02:01 +0000 |
| Subject: | Doc #69735 [Opn]: array_splice() return value could be confusing | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12383@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69735&edit=1
ID: 69735
User updated by: chealer at gmail dot com
Reported by: chealer at gmail dot com
Summary: array_splice() return value could be confusing
Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Note that while I do think my suggestion might have sufficed to prevent my mistake, I did not mean
to imply that explicitly warning that the array returned does not contain the remaining elements was
superfluous. I find the behavior somewhat unintuitive, and that seems to be confirmed by the most
voted comment ( http://php.net/function.array-splice#106244
). A greater protection against misunderstanding may be warranted.
Previous Comments:
------------------------------------------------------------------------
[2015-05-31 18:50:44] chealer at gmail dot com
Description:
------------
I spent 10 minutes debugging why
$foo = array_splice($foo, 0, 1);
would remove the wrong element from a 2-element array. I then realized I has misread the
documentation:
---
From manual page: http://www.php.net/function.array-splice
---
Return Values ¶
Returns the array consisting of the extracted elements.
----
I had hastily read the above as "Returns the array without the extracted elements."
There is no way I could have been confused had I carefully read the whole sentence, but the sentence
is still technically incorrect, since several arrays can consist of the extracted elements. I might
not have misunderstood had the sentence read:
Returns an array consisting of the extracted elements.
Otherwise, the documentation could specify which array consisting of the extracted elements is
returned.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69735&edit=1