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

End of function make

End of class Closable.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.76 ms | 1475 KiB | 17 Q