Doc #75640 [NEW]: Legacy compat function for deprecated each()

From: Date: Wed, 06 Dec 2017 13:37:31 +0000
Subject: Doc #75640 [NEW]: Legacy compat function for deprecated each()
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15271@lists.php.net to get a copy of this message
From: oliver at openbrackets dot net Operating system: Any PHP version: 7.2.0 Package: Documentation problem Bug Type: Documentation Problem Bug description:Legacy compat function for deprecated each() 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 bug report at https://bugs.php.net/bug.php?id=75640&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75640&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75640&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75640&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75640&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75640&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75640&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75640&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75640&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75640&r=support Expected behavior: https://bugs.php.net/fix.php?id=75640&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75640&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75640&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75640&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75640&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75640&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75640&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75640&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75640&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75640&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75640&r=mysqlcfg

« previous php.doc.bugs (#15271) next »