3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Closable { public readonly string $key; private bool $closed = false; public function __construct() { $this->key = uniqid('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 ? 'closed' : 'open'); $this->closed = true; } public function __destroy(): void { $this->e('__destroy'); $this->close(); } public static function make(): Closable { return new self(); } } function a(): void { echo "a() start\n"; $a = Closable::make(); 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"; $b?->close(); } } Closable::make(); $foo = Closable::make(); Closable::make(); for ($i = 0; $i <= 10; $i++) { a(); b(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 9
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 9
Branch analysis from position: 16
Branch analysis from position: 9
filename:       /in/tkFYi
function name:  (null)
number of ops:  17
compiled vars:  !0 = $foo, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          1        DO_FCALL                                      0          
   64     2        INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !0, $3
   65     5        INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          6        DO_FCALL                                      0          
   67     7        ASSIGN                                                   !1, 0
          8      > JMP                                                      ->14
   68     9    >   INIT_FCALL                                               'a'
         10        DO_FCALL                                      0          
   69    11        INIT_FCALL                                               'b'
         12        DO_FCALL                                      0          
   67    13        PRE_INC                                                  !1
         14    >   IS_SMALLER_OR_EQUAL                                      !1, 10
         15      > JMPNZ                                                    ~10, ->9
   70    16    > > RETURN                                                   1

Function a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tkFYi
function name:  a
number of ops:  6
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ECHO                                                     'a%28%29+start%0A'
   41     1        INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   42     4        ECHO                                                     'a%28%29+end%0A'
   43     5      > 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
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 = 27
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tkFYi
function name:  b
number of ops:  28
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   ECHO                                                     'b%28%29+start%0A'
   47     1        INIT_STATIC_METHOD_CALL                                  'Closable', 'make'
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   49     4        INIT_FCALL                                               'rand'
          5        SEND_VAL                                                 0
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $4      
          8      > JMPZ                                                     $4, ->13
   50     9    >   NEW                                              $5      'Exception'
         10        SEND_VAL_EX                                              'b%28%29'
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $5
   52    13    >   ECHO                                                     'b%28%29+return%0A'
   53    14        UNSET_CV                                                 !0
   54    15      > FAST_CALL                                                ->22
         16    > > RETURN                                                   null
         17*       JMP                                                      ->20
   55    18  E > > CATCH                                       last         'Exception'
   56    19    >   ECHO                                                     'b%28%29+catch%0A'
   57    20      > FAST_CALL                                                ->22
         21    > > JMP                                                      ->27
   58    22    >   ECHO                                                     'b%28%29+finally%0A'
   59    23        JMP_NULL                                         $7      !0
         24        INIT_METHOD_CALL                                         !0, 'close'
         25        DO_FCALL                                      0          
         26      > FAST_RET                                                 
   61    27    > > 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/tkFYi
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL                                               'uniqid'
          1        SEND_VAL                                                 'closable_'
          2        DO_ICALL                                         $1      
          3        ASSIGN_OBJ                                               'key'
          4        OP_DATA                                                  $1
   12     5        INIT_METHOD_CALL                                         'e'
          6        SEND_VAL_EX                                              '__construct'
          7        DO_FCALL                                      0          
   13     8      > 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/tkFYi
function name:  e
number of ops:  7
compiled vars:  !0 = $out
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        FETCH_OBJ_R                                      ~1      'key'
          2        ECHO                                                     ~1
          3        ECHO                                                     '%3A+'
          4        ECHO                                                     !0
          5        ECHO                                                     '%0A'
   18     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/tkFYi
function name:  close
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_METHOD_CALL                                         'e'
          1        SEND_VAL                                                 'close'
          2        DO_FCALL                                      0          
   23     3        INIT_METHOD_CALL                                         'e'
          4        FETCH_OBJ_R                                      ~1      'closed'
          5      > JMPZ                                                     ~1, ->8
          6    >   QM_ASSIGN                                        ~2      'closed'
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~2      'open'
          9    >   SEND_VAL                                                 ~2
         10        DO_FCALL                                      0          
   24    11        ASSIGN_OBJ                                               'closed'
         12        OP_DATA                                                  <true>
   25    13      > RETURN                                                   null

End of function close

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

End of function __destroy

Function make:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tkFYi
function name:  make
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   NEW                          self                $0      
          1        DO_FCALL                                      0          
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   36     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:
143.2 ms | 1445 KiB | 17 Q