3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function __construct() { $this->id = rand(0,10); } } class Bar { public function getFoo() { static $instance; if (!$instance) { $instance = new Foo(); } return $instance; } } $d = new Bar(); var_dump($d->getFoo()); var_dump($d->getFoo());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pncLq
function name:  (null)
number of ops:  14
compiled vars:  !0 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $1      'Bar'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   20     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'getFoo'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
   21     8        INIT_FCALL                                               'var_dump'
          9        INIT_METHOD_CALL                                         !0, 'getFoo'
         10        DO_FCALL                                      0  $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pncLq
function name:  __construct
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'rand'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 10
          3        DO_ICALL                                         $1      
          4        ASSIGN_OBJ                                               'id'
          5        OP_DATA                                                  $1
          6      > RETURN                                                   null

End of function __construct

End of class Foo.

Class Bar:
Function getfoo:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/pncLq
function name:  getFoo
number of ops:  8
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   BIND_STATIC                                              !0
   10     1        BOOL_NOT                                         ~1      !0
          2      > JMPZ                                                     ~1, ->6
   11     3    >   NEW                                              $2      'Foo'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
   13     6    > > RETURN                                                   !0
   14     7*     > RETURN                                                   null

End of function getfoo

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.57 ms | 1396 KiB | 17 Q