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');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NhUpM
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
   39     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/NhUpM
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/NhUpM
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 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 5
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Found catch point at position: 15
Branch analysis from position: 15
2 jumps found. (Code = 107) Position 1 = 16, Position 2 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 25
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/NhUpM
function name:  retry
number of ops:  34
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                                                      ->29
   23     5    >   INIT_FCALL                                               'key'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !4, $6
   25     9        INIT_USER_CALL                                1          'call_user_func', !2
         10        FETCH_DIM_R                                      ~8      !0, !4
         11        SEND_USER                                                ~8
         12        DO_FCALL                                      0          
   26    13        UNSET_DIM                                                !0, !4
         14      > JMP                                                      ->29
   27    15  E > > CATCH                                       last         'Exception'
   28    16    >   PRE_INC_STATIC_PROP                                      '_currentRetries'
   29    17        FETCH_STATIC_PROP_R          unknown             ~11     '_currentRetries'
         18        IS_SMALLER_OR_EQUAL                                      ~11, !1
         19      > JMPZ                                                     ~12, ->25
   30    20    >   INIT_USER_CALL                                2          'call_user_func', !3
         21        SEND_USER                                                !5
         22        SEND_USER                                                !0
         23        DO_FCALL                                      0          
         24      > JMP                                                      ->29
   32    25    >   NEW                                              $14     'Exception'
         26        SEND_VAL_EX                                              'maxRetries+reached'
         27        DO_FCALL                                      0          
         28      > THROW                                         0          $14
   22    29    >   INIT_FCALL                                               'reset'
         30        SEND_REF                                                 !0
         31        DO_ICALL                                         $16     
         32      > JMPNZ                                                    $16, ->5
   36    33    > > RETURN                                                   null

End of function retry

End of class RetryIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.65 ms | 1400 KiB | 19 Q