3v4l.org

run code in 300+ PHP versions simultaneously
<?php function retry($retries, callable $fn) { while (true) { try { return $fn(); $retries--; } catch (\Exception $e) { if (!$retries) { throw new \Exception('', 0, $e); } } } } $fn = function() { if ($GLOBALS['counter'] > 0) { $GLOBALS['counter']--; throw new \Exception('Try again'); } return 'something successfull'; }; $start = microtime(true); try { $GLOBALS['counter'] = 999999; retry(1000000, $fn); } catch (\Exception $e) {} echo 'Retry finished in: ' . (microtime(true) -$start) . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 14
Branch analysis from position: 14
2 jumps found. (Code = 107) Position 1 = 15, Position 2 = -2
Branch analysis from position: 15
filename:       /in/BOQpu
function name:  (null)
number of ops:  23
compiled vars:  !0 = $fn, !1 = $start, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBOQpu%3A19%240'
          1        ASSIGN                                                   !0, ~3
   28     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   30     6        FETCH_W                      global              $7      'GLOBALS'
          7        ASSIGN_DIM                                               $7, 'counter'
          8        OP_DATA                                                  999999
   31     9        INIT_FCALL                                               'retry'
         10        SEND_VAL                                                 1000000
         11        SEND_VAR                                                 !0
         12        DO_FCALL                                      0          
         13      > JMP                                                      ->15
   32    14  E > > CATCH                                       last         'Exception'
   34    15    >   INIT_FCALL                                               'microtime'
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $10     
         18        SUB                                              ~11     $10, !1
         19        CONCAT                                           ~12     'Retry+finished+in%3A+', ~11
         20        CONCAT                                           ~13     ~12, '%0A'
         21        ECHO                                                     ~13
         22      > RETURN                                                   1

Function retry:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 3
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 8
Branch analysis from position: 8
2 jumps found. (Code = 107) Position 1 = 9, Position 2 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 17
filename:       /in/BOQpu
function name:  retry
number of ops:  19
compiled vars:  !0 = $retries, !1 = $fn, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2      > JMP                                                      ->17
    8     3    >   INIT_DYNAMIC_CALL                                        !1
          4        DO_FCALL                                      0  $3      
          5      > RETURN                                                   $3
    9     6*       PRE_DEC                                                  !0
          7*       JMP                                                      ->17
   10     8  E > > CATCH                                       last         'Exception'
   11     9    >   BOOL_NOT                                         ~5      !0
         10      > JMPZ                                                     ~5, ->17
   12    11    >   NEW                                              $6      'Exception'
         12        SEND_VAL_EX                                              ''
         13        SEND_VAL_EX                                              0
         14        SEND_VAR_EX                                              !2
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $6
    5    17    > > JMPNZ                                                    <true>, ->3
   16    18    > > RETURN                                                   null

End of function retry

Function %00%7Bclosure%7D%2Fin%2FBOQpu%3A19%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BOQpu
function name:  {closure}
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_R                      global              ~0      'GLOBALS'
          1        FETCH_DIM_R                                      ~1      ~0, 'counter'
          2        IS_SMALLER                                               0, ~1
          3      > JMPZ                                                     ~2, ->11
   22     4    >   FETCH_RW                     global              $3      'GLOBALS'
          5        FETCH_DIM_RW                                     $4      $3, 'counter'
          6        PRE_DEC                                                  $4
   23     7        NEW                                              $6      'Exception'
          8        SEND_VAL_EX                                              'Try+again'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $6
   25    11    > > RETURN                                                   'something+successfull'
   26    12*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBOQpu%3A19%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.91 ms | 1403 KiB | 16 Q