php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74850 current() and key() no longer take their parameter by reference
Submitted: 2017-07-03 17:00 UTC Modified: 2017-08-21 11:24 UTC
From: anon at example dot com Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: 7.0.20 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: anon at example dot com
New email:
PHP Version: OS:

 

 [2017-07-03 17:00 UTC] anon at example dot com
Description:
------------
---
From manual page: http://www.php.net/function.current
---

The "effective prototype" of function `current` has actually been changed from

    mixed current ( array &$array )

to

    mixed current ( array $array )

by this commit: https://github.com/php/php-src/commit/745504ea2a7066588af9714f5e32523a3fff4db7

and similarly for function `key`.

That is: Starting with PHP version 7.0.0, current() and key() no longer take their parameter by reference (but always by value).
Moreover, prior to this version, they *preferred* to take it by reference if possible, but still accepted it by value otherwise.

This can be compared to e.g. function `reset`, which always takes its parameter by reference.

---

Here's a live example that current() and key() do not take the parameter by reference in PHP 7 (and also in PHP 4.4.1, maybe an old bug?), contrary to reset():

https://3v4l.org/BNkR8
https://3v4l.org/Eb8bc
https://3v4l.org/7jpXG

And here's a live example that they have long (always?) accepted an argument passed by value (except in PHP 5.0.5, maybe an old bug?), contrary to reset():

https://3v4l.org/COcBl
https://3v4l.org/BPuff
https://3v4l.org/6UVun

---

N.B.: I had started to edit the docs at https://edit.php.net/?project=PHP&perm=en/function.current.php (and also file en/reference/array/functions/key.xml) as anonymous #84338, first just the prototypes (removed the role="reference"), but when I wanted to add a refsect1 role="changelog" then my browser crashed, and after logging in back, now those two files seem locked with a "Work in progress" I cannot cancel...


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-12 16:02 UTC] anon at example dot com
Thanks to whoever cancelled my incomplete "Work in progress" and unlocked the files!
Finally I have been able to submit a complete "Patch for review":

https://edit.php.net/?patchID=2567&project=PHP
 [2017-08-21 11:23 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=342894
Log: Fix bug #74850 current() and key() no longer take their parameter by reference (in PHP 7)

--
Provided by anonymous 84565 ()
 [2017-08-21 11:24 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2017-08-21 11:24 UTC] cmb@php.net
Thanks for the report and the good patch!
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=8433a4a0a25918350f0cca06679b7862f8356b67
Log: Fix bug #74850 current() and key() no longer take their parameter by reference (in PHP 7)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 14:01:31 2024 UTC