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) { if ($retries && $delay) { //do delay } } } throw RetriesExceededException(); } } class Test { public function exception() { throw \Exception(); } } $test = new Test(); try { Retry::immediately(function() use ($test) { $test->exception(); }, 5); } catch (\Exception $e) { var_dump($e); } echo "bar"; //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/FGN0j
function name:  (null)
number of ops:  16
compiled vars:  !0 = $test, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   NEW                                              $2      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   52     3        INIT_STATIC_METHOD_CALL                                  'Retry', 'immediately'
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FFGN0j%3A52%240'
          5        BIND_LEXICAL                                             ~5, !0
          6        SEND_VAL                                                 ~5
          7        SEND_VAL                                                 5
          8        DO_FCALL                                      0          
          9      > JMP                                                      ->14
   54    10  E > > CATCH                                       last         'Exception'
   56    11    >   INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
   59    14    >   ECHO                                                     'bar'
   61    15      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FFGN0j%3A52%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/FGN0j
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/FGN0j
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 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 4
Branch analysis from position: 14
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 = 11, Position 2 = 12
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 13
Branch analysis from position: 13
Branch analysis from position: 13
Branch analysis from position: 12
filename:       /in/FGN0j
function name:  execute
number of ops:  18
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                                                      ->13
   21     4    >   PRE_DEC                                                  !1
   25     5        INIT_DYNAMIC_CALL                                        !0
          6        DO_FCALL                                      0  $5      
          7      > RETURN                                                   $5
          8*       JMP                                                      ->13
   27     9  E > > CATCH                                       last         'Exception'
   29    10    > > JMPZ_EX                                          ~6      !1, ->12
         11    >   BOOL                                             ~6      !2
         12    > > JMPZ                                                     ~6, ->13
   19    13    > > JMPNZ                                                    !1, ->4
   36    14    >   INIT_FCALL_BY_NAME                                       'RetriesExceededException'
         15        DO_FCALL                                      0  $7      
         16      > THROW                                         0          $7
   37    17*     > RETURN                                                   null

End of function execute

End of class Retry.

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

End of function exception

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.38 ms | 1404 KiB | 15 Q