3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Container { private array $services; public function __construct() { $this->services = [ static fn() => doStuff($this), ]; } } $container = new Container; unset($container); var_dump(gc_status()); class Container2 { private array $services; public function __construct() { $this->services = [ static fn(self $self) => doStuff($self), ]; } public function build() { foreach ($this->services as $service) { $service($this); } } } $container = new Container2; unset($container); var_dump(gc_status());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zf8Ig
function name:  (null)
number of ops:  19
compiled vars:  !0 = $container
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $1      'Container'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   16     3        UNSET_CV                                                 !0
   17     4        INIT_FCALL                                               'var_dump'
          5        INIT_FCALL                                               'gc_status'
          6        DO_ICALL                                         $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   38     9        NEW                                              $6      'Container2'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !0, $6
   39    12        UNSET_CV                                                 !0
   40    13        INIT_FCALL                                               'var_dump'
         14        INIT_FCALL                                               'gc_status'
         15        DO_ICALL                                         $9      
         16        SEND_VAR                                                 $9
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Class Container:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zf8Ig
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          1        INIT_ARRAY                                       ~2      ~1
    9     2        ASSIGN_OBJ                                               'services'
   10     3        OP_DATA                                                  ~2
   12     4      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zf8Ig
function name:  {closure}
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL_BY_NAME                                       'doStuff'
          1        FETCH_THIS                                       $0      
          2        SEND_VAR_EX                                              $0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
          5*     > RETURN                                                   null

End of Dynamic Function 0

End of function __construct

End of class Container.

Class Container2:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zf8Ig
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          1        INIT_ARRAY                                       ~2      ~1
   25     2        ASSIGN_OBJ                                               'services'
   26     3        OP_DATA                                                  ~2
   28     4      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zf8Ig
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $self
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        INIT_FCALL_BY_NAME                                       'doStuff'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
          5*     > RETURN                                                   null

End of Dynamic Function 0

End of function __construct

Function build:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 8
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Zf8Ig
function name:  build
number of ops:  10
compiled vars:  !0 = $service
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                      ~1      'services'
          1      > FE_RESET_R                                       $2      ~1, ->8
          2    > > FE_FETCH_R                                               $2, !0, ->8
   33     3    >   INIT_DYNAMIC_CALL                                        !0
          4        FETCH_THIS                                       $3      
          5        SEND_VAR_EX                                              $3
          6        DO_FCALL                                      0          
   32     7      > JMP                                                      ->2
          8    >   FE_FREE                                                  $2
   35     9      > RETURN                                                   null

End of function build

End of class Container2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.72 ms | 1016 KiB | 15 Q