3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 1, 2, 3 ); $maxRetries = 5; class RetryIterator { protected static $_currentRetries = 0; public static function iterate($element) { var_dump($element); if ($element == 2) { throw new Exception('Something went wrong'); } } public static function handleException($e, $array) { var_dump('Exception handled'); } public static function retry(&$array, $maxRetries, $iterateCallback, $handleCallback) { while (reset($array)) { $key = key($array); try { call_user_func($iterateCallback, ($array[$key])); unset($array[$key]); } catch (Exception $e) { static::$_currentRetries++; if (static::$_currentRetries <= $maxRetries) { call_user_func($handleCallback, $e, $array); } else { throw new Exception('maxRetries reached'); } } } } } RetryIterator::retry($arr, 5, 'RetryIterator::iterate', 'RetryIterator::handleException');
Output for git.master, git.master_jit, rfc.property-hooks
int(1) int(2) string(17) "Exception handled" int(2) string(17) "Exception handled" int(2) string(17) "Exception handled" int(2) string(17) "Exception handled" int(2) string(17) "Exception handled" int(2) Fatal error: Uncaught Exception: maxRetries reached in /in/NhUpM:32 Stack trace: #0 /in/NhUpM(39): RetryIterator::retry(Array, 5, 'RetryIterator::...', 'RetryIterator::...') #1 {main} thrown in /in/NhUpM on line 32
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
56.15 ms | 402 KiB | 8 Q