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); var_dump(func_get_args()); if ($element == 2) { throw new Exception('Something went wrong'); } } public static function handleException($e, $array) { var_dump(func_get_args()); var_dump('Exception handled'); } public static function retry(&$array, $maxRetries, $iterateCallback, $handleCallback, $iterateParams = null, $handleParams = null, $iterateCallbackObject = null, $handleCallbackObject = null) { while (!empty($array)) { reset($array); $key = key($array); try { if (!is_object($iterateCallbackObject)) { if (is_array($iterateParams) && !empty($iterateParams)) { array_unshift($handleParams, $array[$key]); call_user_func_array($iterateCallback, $iterateParams); } else { call_user_func($iterateCallback, ($array[$key])); } } else { if (is_array($iterateParams) && !empty($iterateParams)) { array_unshift($handleParams, $array[$key]); call_user_func_array(array($iterateCallbackObject, $iterateCallback), $iterateParams); } else { $iterateCallbackObject->$iterateCallback($array[$key]); } } unset($array[$key]); } catch (Exception $e) { static::$_currentRetries++; if (static::$_currentRetries <= $maxRetries) { if (!is_object($handleCallbackObject)) { if (is_array($handleParams) && !empty($handleParams)) { array_unshift($handleParams, $e, $array); call_user_func_array($handleCallback, $handleParams); } else { call_user_func($handleCallback, $e, $array); } } else { if (is_array($handleParams) && !empty($handleParams)) { array_unshift($handleParams, $e, $array); call_user_func_array(array($handleCallbackObject, $handleCallback), $handleParams); } else { $handleCallbackObject->$handleCallback($e, $array); } } } else { throw new Exception('maxRetries reached'); } } } } } class Foo { public function bar($el, $a = null, $b = null, $c = null) { var_dump(func_get_args()); var_dump($el); if ($el == 2) { throw new Exception('Exception'); } } public function handle($e, $arr, $a = null, $b = null, $c = null) { var_dump(func_get_args()); var_dump('Exception handled'); } } try { RetryIterator::retry($arr, 5, 'RetryIterator::iterate', 'RetryIterator::handleException'); } catch (Exception $e) { } $arr = array(1, false, 2, 3); $foo = new Foo(); try { RetryIterator::retry($arr, 5, 'bar', 'handle', null, null, $foo, $foo); } catch (Exception $e) { } $arr = array(1, false, 2, 3); $foo = new Foo(); try { RetryIterator::retry($arr, 5, 'bar', 'handle', array(1, 2, 3), array(1, 2, 3), $foo, $foo); } catch (Exception $e) { }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 9
Branch analysis from position: 9
2 jumps found. (Code = 107) Position 1 = 10, Position 2 = -2
Branch analysis from position: 10
Found catch point at position: 25
Branch analysis from position: 25
2 jumps found. (Code = 107) Position 1 = 26, Position 2 = -2
Branch analysis from position: 26
Found catch point at position: 41
Branch analysis from position: 41
2 jumps found. (Code = 107) Position 1 = 42, Position 2 = -2
Branch analysis from position: 42
filename:       /in/R6JUC
function name:  (null)
number of ops:  43
compiled vars:  !0 = $arr, !1 = $maxRetries, !2 = $e, !3 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, 5
   86     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      > JMP                                                      ->10
   87     9  E > > CATCH                                       last         'Exception'
   90    10    >   ASSIGN                                                   !0, <array>
   91    11        NEW                                              $8      'Foo'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !3, $8
   93    14        INIT_STATIC_METHOD_CALL                                  'RetryIterator', 'retry'
         15        SEND_REF                                                 !0
         16        SEND_VAL                                                 5
         17        SEND_VAL                                                 'bar'
         18        SEND_VAL                                                 'handle'
         19        SEND_VAL                                                 null
         20        SEND_VAL                                                 null
         21        SEND_VAR                                                 !3
         22        SEND_VAR                                                 !3
         23        DO_FCALL                                      0          
         24      > JMP                                                      ->26
   94    25  E > > CATCH                                       last         'Exception'
   97    26    >   ASSIGN                                                   !0, <array>
   98    27        NEW                                              $13     'Foo'
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !3, $13
  100    30        INIT_STATIC_METHOD_CALL                                  'RetryIterator', 'retry'
         31        SEND_REF                                                 !0
         32        SEND_VAL                                                 5
         33        SEND_VAL                                                 'bar'
         34        SEND_VAL                                                 'handle'
         35        SEND_VAL                                                 <array>
         36        SEND_VAL                                                 <array>
         37        SEND_VAR                                                 !3
         38        SEND_VAR                                                 !3
         39        DO_FCALL                                      0          
         40      > JMP                                                      ->42
  101    41  E > > CATCH                                       last         'Exception'
  103    42    > > RETURN                                                   1

Class RetryIterator:
Function iterate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R6JUC
function name:  iterate
number of ops:  15
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        INIT_FCALL                                               'var_dump'
          5        FUNC_GET_ARGS                                    ~2      
          6        SEND_VAL                                                 ~2
          7        DO_ICALL                                                 
   13     8        IS_EQUAL                                                 !0, 2
          9      > JMPZ                                                     ~4, ->14
   14    10    >   NEW                                              $5      'Exception'
         11        SEND_VAL_EX                                              'Something+went+wrong'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $5
   16    14    > > 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/R6JUC
function name:  handleException
number of ops:  10
compiled vars:  !0 = $e, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        INIT_FCALL                                               'var_dump'
          3        FUNC_GET_ARGS                                    ~2      
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                                 
   20     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAL                                                 'Exception+handled'
          8        DO_ICALL                                                 
   21     9      > RETURN                                                   null

End of function handleexception

Function retry:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 121
Branch analysis from position: 121
2 jumps found. (Code = 44) Position 1 = 124, Position 2 = 9
Branch analysis from position: 124
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 40
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 35
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 121
Branch analysis from position: 121
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 24
Branch analysis from position: 40
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 58
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 121
Branch analysis from position: 121
Branch analysis from position: 45
Found catch point at position: 65
Branch analysis from position: 65
2 jumps found. (Code = 107) Position 1 = 66, Position 2 = -2
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 117
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 94
Branch analysis from position: 73
2 jumps found. (Code = 46) Position 1 = 75, Position 2 = 78
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 79, Position 2 = 89
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
1 jumps found. (Code = 42) Position 1 = 121
Branch analysis from position: 121
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
Branch analysis from position: 78
Branch analysis from position: 94
2 jumps found. (Code = 46) Position 1 = 96, Position 2 = 99
Branch analysis from position: 96
2 jumps found. (Code = 43) Position 1 = 100, Position 2 = 112
Branch analysis from position: 100
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
Branch analysis from position: 112
1 jumps found. (Code = 42) Position 1 = 121
Branch analysis from position: 121
Branch analysis from position: 99
Branch analysis from position: 117
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/R6JUC
function name:  retry
number of ops:  125
compiled vars:  !0 = $array, !1 = $maxRetries, !2 = $iterateCallback, !3 = $handleCallback, !4 = $iterateParams, !5 = $handleParams, !6 = $iterateCallbackObject, !7 = $handleCallbackObject, !8 = $key, !9 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV_INIT                                        !4      null
          5        RECV_INIT                                        !5      null
          6        RECV_INIT                                        !6      null
          7        RECV_INIT                                        !7      null
   24     8      > JMP                                                      ->121
   25     9    >   INIT_FCALL                                               'reset'
         10        SEND_REF                                                 !0
         11        DO_ICALL                                                 
   26    12        INIT_FCALL                                               'key'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !8, $11
   28    16        TYPE_CHECK                                  256  ~13     !6
         17        BOOL_NOT                                         ~14     ~13
         18      > JMPZ                                                     ~14, ->40
   29    19    >   TYPE_CHECK                                  128  ~15     !4
         20      > JMPZ_EX                                          ~15     ~15, ->24
         21    >   ISSET_ISEMPTY_CV                                 ~16     !4
         22        BOOL_NOT                                         ~17     ~16
         23        BOOL                                             ~15     ~17
         24    > > JMPZ                                                     ~15, ->35
   30    25    >   INIT_FCALL                                               'array_unshift'
         26        SEND_REF                                                 !5
         27        FETCH_DIM_R                                      ~18     !0, !8
         28        SEND_VAL                                                 ~18
         29        DO_ICALL                                                 
   31    30        INIT_USER_CALL                                0          'call_user_func_array', !2
         31        SEND_ARRAY                                               !4
         32        CHECK_UNDEF_ARGS                                         
         33        DO_FCALL                                      0          
         34      > JMP                                                      ->39
   33    35    >   INIT_USER_CALL                                1          'call_user_func', !2
         36        FETCH_DIM_R                                      ~21     !0, !8
         37        SEND_USER                                                ~21
         38        DO_FCALL                                      0          
         39    > > JMP                                                      ->63
   36    40    >   TYPE_CHECK                                  128  ~23     !4
         41      > JMPZ_EX                                          ~23     ~23, ->45
         42    >   ISSET_ISEMPTY_CV                                 ~24     !4
         43        BOOL_NOT                                         ~25     ~24
         44        BOOL                                             ~23     ~25
         45    > > JMPZ                                                     ~23, ->58
   37    46    >   INIT_FCALL                                               'array_unshift'
         47        SEND_REF                                                 !5
         48        FETCH_DIM_R                                      ~26     !0, !8
         49        SEND_VAL                                                 ~26
         50        DO_ICALL                                                 
   38    51        INIT_ARRAY                                       ~28     !6
         52        ADD_ARRAY_ELEMENT                                ~28     !2
         53        INIT_USER_CALL                                0          'call_user_func_array', ~28
         54        SEND_ARRAY                                               !4
         55        CHECK_UNDEF_ARGS                                         
         56        DO_FCALL                                      0          
         57      > JMP                                                      ->63
   40    58    >   INIT_METHOD_CALL                                         !6, !2
         59        CHECK_FUNC_ARG                                           
         60        FETCH_DIM_FUNC_ARG                               $30     !0, !8
         61        SEND_FUNC_ARG                                            $30
         62        DO_FCALL                                      0          
   43    63    >   UNSET_DIM                                                !0, !8
         64      > JMP                                                      ->121
   44    65  E > > CATCH                                       last         'Exception'
   45    66    >   PRE_INC_STATIC_PROP                                      '_currentRetries'
   46    67        FETCH_STATIC_PROP_R          unknown             ~33     '_currentRetries'
         68        IS_SMALLER_OR_EQUAL                                      ~33, !1
         69      > JMPZ                                                     ~34, ->117
   47    70    >   TYPE_CHECK                                  256  ~35     !7
         71        BOOL_NOT                                         ~36     ~35
         72      > JMPZ                                                     ~36, ->94
   48    73    >   TYPE_CHECK                                  128  ~37     !5
         74      > JMPZ_EX                                          ~37     ~37, ->78
         75    >   ISSET_ISEMPTY_CV                                 ~38     !5
         76        BOOL_NOT                                         ~39     ~38
         77        BOOL                                             ~37     ~39
         78    > > JMPZ                                                     ~37, ->89
   49    79    >   INIT_FCALL                                               'array_unshift'
         80        SEND_REF                                                 !5
         81        SEND_VAR                                                 !9
         82        SEND_VAR                                                 !0
         83        DO_ICALL                                                 
   50    84        INIT_USER_CALL                                0          'call_user_func_array', !3
         85        SEND_ARRAY                                               !5
         86        CHECK_UNDEF_ARGS                                         
         87        DO_FCALL                                      0          
         88      > JMP                                                      ->93
   52    89    >   INIT_USER_CALL                                2          'call_user_func', !3
         90        SEND_USER                                                !9
         91        SEND_USER                                                !0
         92        DO_FCALL                                      0          
         93    > > JMP                                                      ->116
   55    94    >   TYPE_CHECK                                  128  ~43     !5
         95      > JMPZ_EX                                          ~43     ~43, ->99
         96    >   ISSET_ISEMPTY_CV                                 ~44     !5
         97        BOOL_NOT                                         ~45     ~44
         98        BOOL                                             ~43     ~45
         99    > > JMPZ                                                     ~43, ->112
   56   100    >   INIT_FCALL                                               'array_unshift'
        101        SEND_REF                                                 !5
        102        SEND_VAR                                                 !9
        103        SEND_VAR                                                 !0
        104        DO_ICALL                                                 
   57   105        INIT_ARRAY                                       ~47     !7
        106        ADD_ARRAY_ELEMENT                                ~47     !3
        107        INIT_USER_CALL                                0          'call_user_func_array', ~47
        108        SEND_ARRAY                                               !5
        109        CHECK_UNDEF_ARGS                                         
        110        DO_FCALL                                      0          
        111      > JMP                                                      ->116
   59   112    >   INIT_METHOD_CALL                                         !7, !3
        113        SEND_VAR_EX                                              !9
        114        SEND_VAR_EX                                              !0
        115        DO_FCALL                                      0          
        116    > > JMP                                                      ->121
   63   117    >   NEW                                              $50     'Exception'
        118        SEND_VAL_EX                                              'maxRetries+reached'
        119        DO_FCALL                                      0          
        120      > THROW                                         0          $50
   24   121    >   ISSET_ISEMPTY_CV                                 ~52     !0
        122        BOOL_NOT                                         ~53     ~52
        123      > JMPNZ                                                    ~53, ->9
   67   124    > > RETURN                                                   null

End of function retry

End of class RetryIterator.

Class Foo:
Function bar:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R6JUC
function name:  bar
number of ops:  18
compiled vars:  !0 = $el, !1 = $a, !2 = $b, !3 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
          3        RECV_INIT                                        !3      null
   73     4        INIT_FCALL                                               'var_dump'
          5        FUNC_GET_ARGS                                    ~4      
          6        SEND_VAL                                                 ~4
          7        DO_ICALL                                                 
   74     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
   75    11        IS_EQUAL                                                 !0, 2
         12      > JMPZ                                                     ~7, ->17
   76    13    >   NEW                                              $8      'Exception'
         14        SEND_VAL_EX                                              'Exception'
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $8
   78    17    > > RETURN                                                   null

End of function bar

Function handle:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R6JUC
function name:  handle
number of ops:  13
compiled vars:  !0 = $e, !1 = $arr, !2 = $a, !3 = $b, !4 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
          3        RECV_INIT                                        !3      null
          4        RECV_INIT                                        !4      null
   81     5        INIT_FCALL                                               'var_dump'
          6        FUNC_GET_ARGS                                    ~5      
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                                 
   82     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAL                                                 'Exception+handled'
         11        DO_ICALL                                                 
   83    12      > RETURN                                                   null

End of function handle

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.87 ms | 1420 KiB | 21 Q