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 new RetriesExceededException(); } } class Test { public function exception() { throw \Exception(); } } $test = new Test(); try { Retry::immediately(function() use ($test) { $test->exception(); }); } 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 = 13
Branch analysis from position: 13
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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OnbRW
function name:  (null)
number of ops:  14
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%2FOnbRW%3A52%240'
          5        BIND_LEXICAL                                             ~5, !0
          6        SEND_VAL                                                 ~5
          7        DO_FCALL                                      0          
          8      > JMP                                                      ->13
   54     9  E > > CATCH                                       last         'Exception'
   56    10    >   INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
   60    13    > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FOnbRW%3A52%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OnbRW
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%2FOnbRW%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/OnbRW
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/OnbRW
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 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
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: 7
Branch analysis from position: 7
2 jumps found. (Code = 107) Position 1 = 8, Position 2 = -2
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 11
Branch analysis from position: 11
Branch analysis from position: 11
Branch analysis from position: 10
filename:       /in/OnbRW
function name:  execute
number of ops:  16
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                                                      ->11
   21     4    >   PRE_DEC                                                  !1
   25     5      > RETURN                                                   !0
          6*       JMP                                                      ->11
   27     7  E > > CATCH                                       last         'Exception'
   29     8    > > JMPZ_EX                                          ~5      !1, ->10
          9    >   BOOL                                             ~5      !2
         10    > > JMPZ                                                     ~5, ->11
   19    11    > > JMPNZ                                                    !1, ->4
   36    12    >   NEW                                              $6      'RetriesExceededException'
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $6
   37    15*     > 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/OnbRW
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:
176.62 ms | 1396 KiB | 15 Q