Req #79411 [NEW]: Support `break` for array_walk/array_walk_recursive

From: Date: Tue, 24 Mar 2020 08:53:50 +0000
Subject: Req #79411 [NEW]: Support `break` for array_walk/array_walk_recursive
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226246@lists.php.net to get a copy of this message
From: 6562680 at gmail dot com Operating system: Win10 PHP version: 7.3.16 Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:Support break for array_walk/array_walk_recursive Description: ------------ Am using array_walk/*_recursive to work with reports (seems like): ``` [ 'created' => [], 'updated' => [], // * => [] ] ``` When we have large amount of records we should run 10000 callbacks even if statement ``` static $break = false; if ($break) return null; $break = true; ``` was declared The solution could be ``` class BreakException extends \Exception {} try { array_walk_recursive($array, function () { throw new BreakException(); }); } catch (Exception $e) { } ``` Would be great to implement some statement like foreach break to avoid building stack trace while using that feature (because of foreach supports only single level traversing) Thank you. Test script: --------------- - -- Edit bug report at https://bugs.php.net/bug.php?id=79411&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79411&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79411&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79411&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79411&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79411&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79411&r=support Expected behavior: https://bugs.php.net/fix.php?id=79411&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79411&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79411&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79411&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79411&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79411&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79411&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79411&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79411&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79411&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79411&r=mysqlcfg

« previous php.bugs (#226246) next »