php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #69735 array_splice() return value could be confusing
Submitted: 2015-05-31 18:50 UTC Modified: 2015-12-18 21:14 UTC
From: chealer at gmail dot com Assigned: tpunt (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chealer at gmail dot com
New email:
PHP Version: OS:

 

 [2015-05-31 18:50 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-31 19:02 UTC] chealer at gmail dot com
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.
 [2015-12-18 21:12 UTC] tpunt@php.net
Automatic comment from SVN on behalf of tpunt
Revision: http://svn.php.net/viewvc/?view=revision&revision=338309
Log: Resolves doc bug #69735
 [2015-12-18 21:12 UTC] tpunt@php.net
-Assigned To: +Assigned To: tpunt
 [2015-12-18 21:13 UTC] tpunt@php.net
It's a minor edit, but I do agree that saying that "the array" implies the original array, whereas "an array" would imply a new array.

Resolved with commit: https://svn.php.net/viewvc?view=revision&revision=338309
 [2015-12-18 21:14 UTC] tpunt@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 11:01:35 2025 UTC