Doc #75640 [Opn->Wfx]: Legacy compat function for deprecated each()
| From: | peehaa@php.net | Date: | Fri, 26 Apr 2019 03:27:30 +0000 |
| Subject: | Doc #75640 [Opn->Wfx]: Legacy compat function for deprecated each() | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-16615@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75640&edit=1
ID: 75640
Updated by: peehaa@php.net
Reported by: oliver at openbrackets dot net
Summary: Legacy compat function for deprecated each()
-Status: Open
+Status: Wont fix
Type: Documentation Problem
Package: Documentation problem
Operating System: Any
PHP Version: 7.2.0
Block user comment: N
Private report: N
New Comment:
Not sure I agree the docs are the best platform for this.
Previous Comments:
------------------------------------------------------------------------
[2017-12-06 13:37:26] oliver at openbrackets dot net
Description:
------------
Tried to put this in user notes, but that system doesn't appear to work.
I fully agree with deprecating each(). However there are lots of old third party libraries out there
which use it in arcane ways.
Refactoring third party code is not fun. So suggest to provide a workaround in the docs to keep
these working.
Suggest to put a "leach() = Legacy each()" function in docs, with code similar to that in
"test script" field.
Test script:
---------------
<?php
/**
* leach() = "legacy each"
*
* replacement for deprecated each() for php7.2
* use this if refactoring would be too painful and performance is not relevant
*
*/
function leach(&$arr)
{
$k = key($arr);
if ($k === null)
{
// https://secure.php.net/manual/en/function.each.php
// If the internal pointer for the array points past the end of the array contents, each()
returns FALSE.
return false;
}
else
{
// https://secure.php.net/manual/en/function.each.php
// Returns the current key and value pair from the array
// array. This pair is returned in a four-element array, with the
// keys 0, 1, key, and value. Elements 0 and key contain the key
// name of the array element, and 1 and value contain the data.
$v = current($arr);
$retval = [
1 => $v,
'value' => $v,
0 => $k,
'key' => $k
];
// https://secure.php.net/manual/en/function.each.php
// After each() has executed, the array cursor will be left on the
// next element of the array, or past the last element if it hits the
// end of the array. You have to use reset() if you want to traverse
// the array again using each.
next($arr);
return $retval;
}
}
?>
Expected result:
----------------
docs for each() revised
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75640&edit=1