3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Closable { public readonly string $key; private bool $closed = false; public function __construct( ?string $key = null, ) { $this->key = uniqid($key ?: 'closable_'); $this->e('__construct'); } private function e(string $out): void { echo $this->key, ': ', $out, "\n"; } public function close(): void { $this->e('close'); $this->e($this->closed ? 'already closed' : 'closing'); $this->closed = true; } public function __destruct() { $this->e('__destruct'); $this->close(); } public static function make(...$params): Closable { return new self(...$params); } } function a(): void { echo "a() start\n"; $a = Closable::make('$a'); echo "a() end\n"; } function b(): void { echo "b() start\n"; $b = Closable::make('$b'); try { if (rand(0,1)) { throw new Exception('b()'); } echo "b() return\n"; unset($b); return; } catch (Exception) { echo "b() catch\n"; } finally { echo "b() finally\n"; isset($b) ? $b->close() : null; } } Closable::make('first'); $foo = Closable::make('$foo'); Closable::make('third'); for ($i = 0; $i <= 10; $i++) { a(); b(); }
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 = 19, Position 2 = 12
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 12
Branch analysis from position: 19
Branch analysis from position: 12
filename:       /in/87U9d
function name:  (null)
number of ops:  20
compiled vars:  !0 = $foo, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          1        SEND_VAL                                                 'first'
          2        DO_FCALL                                      0          
   65     3        INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          4        SEND_VAL                                                 '%24foo'
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !0, $3
   66     7        INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          8        SEND_VAL                                                 'third'
          9        DO_FCALL                                      0          
   68    10        ASSIGN                                                   !1, 0
         11      > JMP                                                      ->17
   69    12    >   INIT_FCALL                                               'a'
         13        DO_FCALL                                      0          
   70    14        INIT_FCALL                                               'b'
         15        DO_FCALL                                      0          
   68    16        PRE_INC                                                  !1
         17    >   IS_SMALLER_OR_EQUAL                                      !1, 10
         18      > JMPNZ                                                    ~10, ->12
   71    19    > > RETURN                                                   1

Function a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/87U9d
function name:  a
number of ops:  7
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   ECHO                                                     'a%28%29+start%0A'
   42     1        INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          2        SEND_VAL                                                 '%24a'
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   43     5        ECHO                                                     'a%28%29+end%0A'
   44     6      > RETURN                                                   null

End of function a

Function b:
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
2 jumps found. (Code = 162) Position 1 = 23, Position 2 = 17
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 163) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 163) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 19
Branch analysis from position: 19
2 jumps found. (Code = 107) Position 1 = 20, Position 2 = -2
Branch analysis from position: 20
2 jumps found. (Code = 162) Position 1 = 23, Position 2 = 22
Branch analysis from position: 23
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/87U9d
function name:  b
number of ops:  34
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   ECHO                                                     'b%28%29+start%0A'
   48     1        INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          2        SEND_VAL                                                 '%24b'
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   50     5        INIT_FCALL                                               'rand'
          6        SEND_VAL                                                 0
          7        SEND_VAL                                                 1
          8        DO_ICALL                                         $4      
          9      > JMPZ                                                     $4, ->14
   51    10    >   NEW                                              $5      'Exception'
         11        SEND_VAL_EX                                              'b%28%29'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $5
   53    14    >   ECHO                                                     'b%28%29+return%0A'
   54    15        UNSET_CV                                                 !0
   55    16      > FAST_CALL                                                ->23
         17    > > RETURN                                                   null
         18*       JMP                                                      ->21
   56    19  E > > CATCH                                       last         'Exception'
   57    20    >   ECHO                                                     'b%28%29+catch%0A'
   58    21      > FAST_CALL                                                ->23
         22    > > JMP                                                      ->33
   59    23    >   ECHO                                                     'b%28%29+finally%0A'
   60    24        ISSET_ISEMPTY_CV                                         !0
         25      > JMPZ                                                     ~7, ->30
         26    >   INIT_METHOD_CALL                                         !0, 'close'
         27        DO_FCALL                                      0  $8      
         28        QM_ASSIGN                                        ~9      $8
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~9      null
         31    >   FREE                                                     ~9
         32      > FAST_RET                                                 
   62    33    > > RETURN                                                   null

End of function b

Class Closable:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/87U9d
function name:  __construct
number of ops:  12
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV_INIT                                        !0      null
   11     1        INIT_FCALL                                               'uniqid'
          2        JMP_SET                                          ~2      !0, ->4
          3        QM_ASSIGN                                        ~2      'closable_'
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        ASSIGN_OBJ                                               'key'
          7        OP_DATA                                                  $3
   13     8        INIT_METHOD_CALL                                         'e'
          9        SEND_VAL_EX                                              '__construct'
         10        DO_FCALL                                      0          
   14    11      > RETURN                                                   null

End of function __construct

Function e:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/87U9d
function name:  e
number of ops:  7
compiled vars:  !0 = $out
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        FETCH_OBJ_R                                      ~1      'key'
          2        ECHO                                                     ~1
          3        ECHO                                                     '%3A+'
          4        ECHO                                                     !0
          5        ECHO                                                     '%0A'
   19     6      > RETURN                                                   null

End of function e

Function close:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/87U9d
function name:  close
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_METHOD_CALL                                         'e'
          1        SEND_VAL                                                 'close'
          2        DO_FCALL                                      0          
   24     3        INIT_METHOD_CALL                                         'e'
          4        FETCH_OBJ_R                                      ~1      'closed'
          5      > JMPZ                                                     ~1, ->8
          6    >   QM_ASSIGN                                        ~2      'already+closed'
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~2      'closing'
          9    >   SEND_VAL                                                 ~2
         10        DO_FCALL                                      0          
   25    11        ASSIGN_OBJ                                               'closed'
         12        OP_DATA                                                  <true>
   26    13      > RETURN                                                   null

End of function close

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/87U9d
function name:  __destruct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_METHOD_CALL                                         'e'
          1        SEND_VAL                                                 '__destruct'
          2        DO_FCALL                                      0          
   31     3        INIT_METHOD_CALL                                         'close'
          4        DO_FCALL                                      0          
   32     5      > RETURN                                                   null

End of function __destruct

Function make:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/87U9d
function name:  make
number of ops:  9
compiled vars:  !0 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV_VARIADIC                                    !0      
   36     1        NEW                          self                $1      
          2        SEND_UNPACK                                              !0
          3        CHECK_UNDEF_ARGS                                         
          4        DO_FCALL                                      1          
          5        VERIFY_RETURN_TYPE                                       $1
          6      > RETURN                                                   $1
   37     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function make

End of class Closable.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.72 ms | 1449 KiB | 17 Q