3v4l.org

run code in 500+ PHP versions simultaneously
<?php class SomeService { public string $something; } // before, in 10.1 class BaseOld { protected SomeService $test; public function __construct(?SomeService $test = NULL) { if ($test === NULL) { $test = new SomeService(); $test->something = 'fallback'; } $this->test = $test; } public function printTest(): void { print __CLASS__ . "\t" . $this->test->something . "\n"; } } // after class BaseNew { private SomeService $test; public function __construct(?SomeService $test = NULL) { if ($test === NULL) { $test = new SomeService(); $test->something = 'fallback'; } $this->test = $test; } public function printTest(): void { print __CLASS__ . "\t" . $this->test->something . "\n"; } } //NOTE: IDENTICAL! // class FooOld extends BaseOld { // protected $test; // public function __construct() { // parent::__construct(); // $this->test = new SomeService(); // $this->test->something = 'subclass'; // } // } class FooNew extends BaseNew { protected $test; public function __construct() { parent::__construct(); $this->test = new SomeService(); $this->test->something = 'subclass'; } } // $f = new FooOld(); // $f->printTest(); $f = new FooNew(); $f->printTest();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m6AJL
function name:  (null)
number of ops:  6
compiled vars:  !0 = $f
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   56     0  E >   NEW                                                  $1      'FooNew'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   57     3        INIT_METHOD_CALL                                             !0, 'printTest'
          4        DO_FCALL                                          0          
          5      > RETURN                                                       1

Class SomeService: [no user functions]
Class BaseOld:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/m6AJL
function name:  __construct
number of ops:  11
compiled vars:  !0 = $test
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV_INIT                                            !0      null
   11     1        TYPE_CHECK                                        2          !0
          2      > JMPZ                                                         ~1, ->8
   12     3    >   NEW                                                  $2      'SomeService'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !0, $2
   13     6        ASSIGN_OBJ                                                   !0, 'something'
          7        OP_DATA                                                      'fallback'
   15     8    >   ASSIGN_OBJ                                                   'test'
          9        OP_DATA                                                      !0
   16    10      > RETURN                                                       null

End of function __construct

Function printtest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m6AJL
function name:  printTest
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   FETCH_OBJ_R                                          ~0      'test'
          1        FETCH_OBJ_R                                          ~1      ~0, 'something'
          2        CONCAT                                               ~2      'BaseOld%09', ~1
          3        CONCAT                                               ~3      ~2, '%0A'
          4        ECHO                                                         ~3
   19     5      > RETURN                                                       null

End of function printtest

End of class BaseOld.

Class BaseNew:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/m6AJL
function name:  __construct
number of ops:  11
compiled vars:  !0 = $test
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV_INIT                                            !0      null
   25     1        TYPE_CHECK                                        2          !0
          2      > JMPZ                                                         ~1, ->8
   26     3    >   NEW                                                  $2      'SomeService'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !0, $2
   27     6        ASSIGN_OBJ                                                   !0, 'something'
          7        OP_DATA                                                      'fallback'
   29     8    >   ASSIGN_OBJ                                                   'test'
          9        OP_DATA                                                      !0
   30    10      > RETURN                                                       null

End of function __construct

Function printtest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m6AJL
function name:  printTest
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                          ~0      'test'
          1        FETCH_OBJ_R                                          ~1      ~0, 'something'
          2        CONCAT                                               ~2      'BaseNew%09', ~1
          3        CONCAT                                               ~3      ~2, '%0A'
          4        ECHO                                                         ~3
   33     5      > RETURN                                                       null

End of function printtest

End of class BaseNew.

Class FooNew:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m6AJL
function name:  __construct
number of ops:  10
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   48     0  E >   INIT_STATIC_METHOD_CALL                                      
          1        DO_FCALL                                          0          
   49     2        NEW                                                  $2      'SomeService'
          3        DO_FCALL                                          0          
          4        ASSIGN_OBJ                                                   'test'
          5        OP_DATA                                                      $2
   50     6        FETCH_OBJ_W                                          $4      'test'
          7        ASSIGN_OBJ                                                   $4, 'something'
          8        OP_DATA                                                      'subclass'
   51     9      > RETURN                                                       null

End of function __construct

Function printtest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m6AJL
function name:  printTest
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                          ~0      'test'
          1        FETCH_OBJ_R                                          ~1      ~0, 'something'
          2        CONCAT                                               ~2      'BaseNew%09', ~1
          3        CONCAT                                               ~3      ~2, '%0A'
          4        ECHO                                                         ~3
   33     5      > RETURN                                                       null

End of function printtest

End of class FooNew.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
150.54 ms | 484 KiB | 7 Q