3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 1, 2, 3 ); $maxRetries = 5; class RetryCatch { 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)) { $useIterateParams = $iterateParams; array_unshift($useIterateParams, $array[$key]); call_user_func_array($iterateCallback, $useIterateParams); } else { call_user_func($iterateCallback, ($array[$key])); } } else { if (is_array($iterateParams) && !empty($iterateParams)) { $useIterateParams = $iterateParams; array_unshift($useIterateParams, $array[$key]); // var_dump($iterateParams); die(); call_user_func_array(array($iterateCallbackObject, $iterateCallback), $useIterateParams); } 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)) { $useHandleParams = $handleParams; array_unshift($useHandleParams, $e, $array); call_user_func_array($handleCallback, $useHandleParams); } else { call_user_func($handleCallback, $e, $array); } } else { if (is_array($handleParams) && !empty($handleParams)) { $useHandleParams = $handleParams; array_unshift($useHandleParams, $e, $array); call_user_func_array(array($handleCallbackObject, $handleCallback), $useHandleParams); } else { $handleCallbackObject->$handleCallback($e, $array); } } } else { throw new Exception('RetryCatch::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 { RetryCatch::retry($arr, 5, 'RetryCatch::iterate', 'RetryCatch::handleException'); } catch (Exception $e) { } $arr = array(1, false, 2, 3); $foo = new Foo(); try { RetryCatch::retry($arr, 5, 'bar', 'handle', null, null, $foo, $foo); } catch (Exception $e) { } $arr = array(1, false, 2, 3); $foo = new Foo(); try { RetryCatch::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/meNKI
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
   91     2        INIT_STATIC_METHOD_CALL                                  'RetryCatch', 'retry'
          3        SEND_REF                                                 !0
          4        SEND_VAL                                                 5
          5        SEND_VAL                                                 'RetryCatch%3A%3Aiterate'
          6        SEND_VAL                                                 'RetryCatch%3A%3AhandleException'
          7        DO_FCALL                                      0          
          8      > JMP                                                      ->10
   92     9  E > > CATCH                                       last         'Exception'
   95    10    >   ASSIGN                                                   !0, <array>
   96    11        NEW                                              $8      'Foo'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !3, $8
   98    14        INIT_STATIC_METHOD_CALL                                  'RetryCatch', '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
   99    25  E > > CATCH                                       last         'Exception'
  102    26    >   ASSIGN                                                   !0, <array>
  103    27        NEW                                              $13     'Foo'
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !3, $13
  105    30        INIT_STATIC_METHOD_CALL                                  'RetryCatch', '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
  106    41  E > > CATCH                                       last         'Exception'
  108    42    > > RETURN                                                   1

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

End of function retry

End of class RetryCatch.

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/meNKI
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
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
          3        RECV_INIT                                        !3      null
   78     4        INIT_FCALL                                               'var_dump'
          5        FUNC_GET_ARGS                                    ~4      
          6        SEND_VAL                                                 ~4
          7        DO_ICALL                                                 
   79     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
   80    11        IS_EQUAL                                                 !0, 2
         12      > JMPZ                                                     ~7, ->17
   81    13    >   NEW                                              $8      'Exception'
         14        SEND_VAL_EX                                              'Exception'
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $8
   83    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/meNKI
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
-------------------------------------------------------------------------------------
   85     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
          3        RECV_INIT                                        !3      null
          4        RECV_INIT                                        !4      null
   86     5        INIT_FCALL                                               'var_dump'
          6        FUNC_GET_ARGS                                    ~5      
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                                 
   87     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAL                                                 'Exception+handled'
         11        DO_ICALL                                                 
   88    12      > RETURN                                                   null

End of function handle

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.96 ms | 1420 KiB | 21 Q