3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $name; public function __construct($name) { $this->name = $name; } } class Bar { private $foo; public function __construct(Foo $foo = null, $default = 'default') { $this->foo = $foo ?: new Foo($default); } public function getFooName() { return $this->foo->name; } } $foo = new Foo('John'); $bar = new Bar($foo); echo $bar->getFooName(), PHP_EOL; // John $bar = new Bar(); echo $bar->getFooName(), PHP_EOL; // default $bar = new Bar(null, 'something'); echo $bar->getFooName(), PHP_EOL; // something
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hnbVL
function name:  (null)
number of ops:  29
compiled vars:  !0 = $foo, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $2      'Foo'
          1        SEND_VAL_EX                                              'John'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   29     4        NEW                                              $5      'Bar'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $5
   30     8        INIT_METHOD_CALL                                         !1, 'getFooName'
          9        DO_FCALL                                      0  $8      
         10        ECHO                                                     $8
         11        ECHO                                                     '%0A'
   32    12        NEW                                              $9      'Bar'
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !1, $9
   33    15        INIT_METHOD_CALL                                         !1, 'getFooName'
         16        DO_FCALL                                      0  $12     
         17        ECHO                                                     $12
         18        ECHO                                                     '%0A'
   35    19        NEW                                              $13     'Bar'
         20        SEND_VAL_EX                                              null
         21        SEND_VAL_EX                                              'something'
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !1, $13
   36    24        INIT_METHOD_CALL                                         !1, 'getFooName'
         25        DO_FCALL                                      0  $16     
         26        ECHO                                                     $16
         27        ECHO                                                     '%0A'
         28      > RETURN                                                   1

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

End of function __construct

End of class Foo.

Class Bar:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hnbVL
function name:  __construct
number of ops:  10
compiled vars:  !0 = $foo, !1 = $default
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      'default'
   19     2        JMP_SET                                          ~3      !0, ->7
          3        NEW                                              $4      'Foo'
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
          6        QM_ASSIGN                                        ~3      $4
          7        ASSIGN_OBJ                                               'foo'
          8        OP_DATA                                                  ~3
   20     9      > RETURN                                                   null

End of function __construct

Function getfooname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hnbVL
function name:  getFooName
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   FETCH_OBJ_R                                      ~0      'foo'
          1        FETCH_OBJ_R                                      ~1      ~0, 'name'
          2      > RETURN                                                   ~1
   25     3*     > RETURN                                                   null

End of function getfooname

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.87 ms | 1399 KiB | 13 Q