3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { private $id; public $handle; public function __construct($id) { $this->id = $id; $this->handle = fopen('php://memory', 'r+'); echo $this->id . ' - construct' . PHP_EOL; } public function __destruct() { echo $this->id . ' - destruct' . PHP_EOL; fclose($this->handle); } public function bar() { echo $this->id . ' - bar - ' . get_resource_type($this->handle) . PHP_EOL; return $this; } public static function create($id) { return new Foo($id); } } $foo = Foo::create(1); var_dump( $foo->bar()->handle ); var_dump( Foo::create(2)->bar()->handle );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NjpYP
function name:  (null)
number of ops:  20
compiled vars:  !0 = $foo
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   INIT_STATIC_METHOD_CALL                                      'Foo', 'create'
          1        SEND_VAL                                                     1
          2        DO_FCALL                                          0  $1      
          3        ASSIGN                                                       !0, $1
   33     4        INIT_FCALL                                                   'var_dump'
          5        INIT_METHOD_CALL                                             !0, 'bar'
          6        DO_FCALL                                          0  $3      
          7        FETCH_OBJ_R                                          ~4      $3, 'handle'
          8        SEND_VAL                                                     ~4
          9        DO_ICALL                                                     
   35    10        INIT_FCALL                                                   'var_dump'
         11        INIT_STATIC_METHOD_CALL                                      'Foo', 'create'
         12        SEND_VAL                                                     2
         13        DO_FCALL                                          0  $6      
         14        INIT_METHOD_CALL                                             $6, 'bar'
         15        DO_FCALL                                          0  $7      
         16        FETCH_OBJ_R                                          ~8      $7, 'handle'
         17        SEND_VAL                                                     ~8
         18        DO_ICALL                                                     
         19      > RETURN                                                       1

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NjpYP
function name:  __construct
number of ops:  14
compiled vars:  !0 = $id
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
    8     1        ASSIGN_OBJ                                                   'id'
          2        OP_DATA                                                      !0
    9     3        INIT_FCALL                                                   'fopen'
          4        SEND_VAL                                                     'php%3A%2F%2Fmemory'
          5        SEND_VAL                                                     'r%2B'
          6        DO_ICALL                                             $3      
          7        ASSIGN_OBJ                                                   'handle'
          8        OP_DATA                                                      $3
   11     9        FETCH_OBJ_R                                          ~4      'id'
         10        CONCAT                                               ~5      ~4, '+-+construct'
         11        CONCAT                                               ~6      ~5, '%0A'
         12        ECHO                                                         ~6
   12    13      > RETURN                                                       null

End of function __construct

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NjpYP
function name:  __destruct
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   FETCH_OBJ_R                                          ~0      'id'
          1        CONCAT                                               ~1      ~0, '+-+destruct'
          2        CONCAT                                               ~2      ~1, '%0A'
          3        ECHO                                                         ~2
   17     4        INIT_FCALL                                                   'fclose'
          5        FETCH_OBJ_R                                          ~3      'handle'
          6        SEND_VAL                                                     ~3
          7        DO_ICALL                                                     
   18     8      > RETURN                                                       null

End of function __destruct

Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NjpYP
function name:  bar
number of ops:  12
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   FETCH_OBJ_R                                          ~0      'id'
          1        CONCAT                                               ~1      ~0, '+-+bar+-+'
          2        INIT_FCALL                                                   'get_resource_type'
          3        FETCH_OBJ_R                                          ~2      'handle'
          4        SEND_VAL                                                     ~2
          5        DO_ICALL                                             $3      
          6        CONCAT                                               ~4      ~1, $3
          7        CONCAT                                               ~5      ~4, '%0A'
          8        ECHO                                                         ~5
   23     9        FETCH_THIS                                           ~6      
         10      > RETURN                                                       ~6
   24    11*     > RETURN                                                       null

End of function bar

Function create:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NjpYP
function name:  create
number of ops:  6
compiled vars:  !0 = $id
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   RECV                                                 !0      
   27     1        NEW                                                  $1      'Foo'
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0          
          4      > RETURN                                                       $1
   28     5*     > RETURN                                                       null

End of function create

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.36 ms | 2860 KiB | 17 Q