3v4l.org

run code in 300+ PHP versions simultaneously
<?php class RetriesExceededException extends \Exception {} class Retry { static public function withDelay(callable $fn, $retries, $delay) { return self::execute($fn, $retries, $delay); } static public function immediately(callable $fn, $retries) { return self::execute($fn, $retries); } static private function execute(callable $fn, $retries, $delay = null) { while ($retries) { $retries--; try { return $fn(); } catch (\Exception $e) { echo $retries; if ($retries && $delay) { //do delay } } } throw new RetriesExceededException(); } } class Test { public function doSomething() { throw new \Exception(); } } $test = new Test(); try { Retry::immediately(function() use ($test) { $test->doSomething(); }, 5); } catch (\Exception $e) { var_dump($e); } //Retry::withDelay($fn, $retries, $delay); //Retry::immediately($fn, $retries);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 10
Branch analysis from position: 10
2 jumps found. (Code = 107) Position 1 = 11, Position 2 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6OrSe
function name:  (null)
number of ops:  15
compiled vars:  !0 = $test, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   NEW                                              $2      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   54     3        INIT_STATIC_METHOD_CALL                                  'Retry', 'immediately'
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F6OrSe%3A54%240'
          5        BIND_LEXICAL                                             ~5, !0
          6        SEND_VAL                                                 ~5
          7        SEND_VAL                                                 5
          8        DO_FCALL                                      0          
          9      > JMP                                                      ->14
   56    10  E > > CATCH                                       last         'Exception'
   58    11    >   INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
   63    14    > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F6OrSe%3A54%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6OrSe
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   BIND_STATIC                                              !0
          1        INIT_METHOD_CALL                                         !0, 'doSomething'
          2        DO_FCALL                                      0          
          3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F6OrSe%3A54%240

Class RetriesExceededException: [no user functions]
Class Retry:
Function withdelay:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6OrSe
function name:  withDelay
number of ops:  10
compiled vars:  !0 = $fn, !1 = $retries, !2 = $delay
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    9     3        INIT_STATIC_METHOD_CALL                                  'execute'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        DO_FCALL                                      0  $3      
          8      > RETURN                                                   $3
   10     9*     > RETURN                                                   null

End of function withdelay

Function immediately:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6OrSe
function name:  immediately
number of ops:  8
compiled vars:  !0 = $fn, !1 = $retries
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_STATIC_METHOD_CALL                                  'execute'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
   15     7*     > RETURN                                                   null

End of function immediately

Function execute:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 4
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 4
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
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 14
Branch analysis from position: 14
Branch analysis from position: 14
Branch analysis from position: 13
filename:       /in/6OrSe
function name:  execute
number of ops:  19
compiled vars:  !0 = $fn, !1 = $retries, !2 = $delay, !3 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   19     3      > JMP                                                      ->14
   21     4    >   PRE_DEC                                                  !1
   25     5        INIT_DYNAMIC_CALL                                        !0
          6        DO_FCALL                                      0  $5      
          7      > RETURN                                                   $5
          8*       JMP                                                      ->14
   27     9  E > > CATCH                                       last         'Exception'
   29    10    >   ECHO                                                     !1
   31    11      > JMPZ_EX                                          ~6      !1, ->13
         12    >   BOOL                                             ~6      !2
         13    > > JMPZ                                                     ~6, ->14
   19    14    > > JMPNZ                                                    !1, ->4
   38    15    >   NEW                                              $7      'RetriesExceededException'
         16        DO_FCALL                                      0          
         17      > THROW                                         0          $7
   39    18*     > RETURN                                                   null

End of function execute

End of class Retry.

Class Test:
Function dosomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/6OrSe
function name:  doSomething
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   NEW                                              $0      'Exception'
          1        DO_FCALL                                      0          
          2      > THROW                                         0          $0
   47     3*     > RETURN                                                   null

End of function dosomething

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.36 ms | 1404 KiB | 15 Q