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 (!empty($array)) { 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');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uCCDM
function name:  (null)
number of ops:  9
compiled vars:  !0 = $arr, !1 = $maxRetries
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, 5
   40     2        INIT_STATIC_METHOD_CALL                                  'RetryIterator', 'retry'
          3        SEND_REF                                                 !0
          4        SEND_VAL                                                 5
          5        SEND_VAL                                                 'RetryIterator%3A%3Aiterate'
          6        SEND_VAL                                                 'RetryIterator%3A%3AhandleException'
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

Class RetryIterator:
Function iterate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uCCDM
function name:  iterate
number of ops:  11
compiled vars:  !0 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'var_dump'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   12     4        IS_EQUAL                                                 !0, 2
          5      > JMPZ                                                     ~2, ->10
   13     6    >   NEW                                              $3      'Exception'
          7        SEND_VAL_EX                                              'Something+went+wrong'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $3
   15    10    > > RETURN                                                   null

End of function iterate

Function handleexception:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uCCDM
function name:  handleException
number of ops:  6
compiled vars:  !0 = $e, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        INIT_FCALL                                               'var_dump'
          3        SEND_VAL                                                 'Exception+handled'
          4        DO_ICALL                                                 
   19     5      > RETURN                                                   null

End of function handleexception

Function retry:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 5
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Found catch point at position: 18
Branch analysis from position: 18
2 jumps found. (Code = 107) Position 1 = 19, Position 2 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 28
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/uCCDM
function name:  retry
number of ops:  36
compiled vars:  !0 = $array, !1 = $maxRetries, !2 = $iterateCallback, !3 = $handleCallback, !4 = $key, !5 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   22     4      > JMP                                                      ->32
   23     5    >   INIT_FCALL                                               'reset'
          6        SEND_REF                                                 !0
          7        DO_ICALL                                                 
   24     8        INIT_FCALL                                               'key'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $7      
         11        ASSIGN                                                   !4, $7
   26    12        INIT_USER_CALL                                1          'call_user_func', !2
         13        FETCH_DIM_R                                      ~9      !0, !4
         14        SEND_USER                                                ~9
         15        DO_FCALL                                      0          
   27    16        UNSET_DIM                                                !0, !4
         17      > JMP                                                      ->32
   28    18  E > > CATCH                                       last         'Exception'
   29    19    >   PRE_INC_STATIC_PROP                                      '_currentRetries'
   30    20        FETCH_STATIC_PROP_R          unknown             ~12     '_currentRetries'
         21        IS_SMALLER_OR_EQUAL                                      ~12, !1
         22      > JMPZ                                                     ~13, ->28
   31    23    >   INIT_USER_CALL                                2          'call_user_func', !3
         24        SEND_USER                                                !5
         25        SEND_USER                                                !0
         26        DO_FCALL                                      0          
         27      > JMP                                                      ->32
   33    28    >   NEW                                              $15     'Exception'
         29        SEND_VAL_EX                                              'maxRetries+reached'
         30        DO_FCALL                                      0          
         31      > THROW                                         0          $15
   22    32    >   ISSET_ISEMPTY_CV                                 ~17     !0
         33        BOOL_NOT                                         ~18     ~17
         34      > JMPNZ                                                    ~18, ->5
   37    35    > > RETURN                                                   null

End of function retry

End of class RetryIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.67 ms | 1400 KiB | 19 Q