3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { public function __construct( private readonly int $a, private readonly string $b, ) { } public function withA(int $a): self { return new self(...(get_defined_vars() + get_object_vars($this))); } public function withB(string $b): self { return new self(...(get_defined_vars() + get_object_vars($this))); } } $f = (new Foo(1, "foo")) ->withA(2) ->withB("bar"); var_dump($f);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XhG90
function name:  (null)
number of ops:  15
compiled vars:  !0 = $f
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   NEW                                                  $1      'Foo'
          1        SEND_VAL_EX                                                  1
          2        SEND_VAL_EX                                                  'foo'
          3        DO_FCALL                                          0          
   23     4        INIT_METHOD_CALL                                             $1, 'withA'
          5        SEND_VAL_EX                                                  2
          6        DO_FCALL                                          0  $3      
   24     7        INIT_METHOD_CALL                                             $3, 'withB'
          8        SEND_VAL_EX                                                  'bar'
          9        DO_FCALL                                          0  $4      
   22    10        ASSIGN                                                       !0, $4
   26    11        INIT_FCALL                                                   'var_dump'
         12        SEND_VAR                                                     !0
         13        DO_ICALL                                                     
         14      > RETURN                                                       1

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

End of function __construct

Function witha:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XhG90
function name:  withA
number of ops:  16
compiled vars:  !0 = $a
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
   13     1        NEW                              self                $1      
          2        INIT_FCALL                                                   'get_defined_vars'
          3        DO_ICALL                                             $2      
          4        INIT_FCALL                                                   'get_object_vars'
          5        FETCH_THIS                                           ~3      
          6        SEND_VAL                                                     ~3
          7        DO_ICALL                                             $4      
          8        ADD                                                  ~5      $2, $4
          9        SEND_UNPACK                                                  ~5
         10        CHECK_UNDEF_ARGS                                             
         11        DO_FCALL                                          1          
         12        VERIFY_RETURN_TYPE                                           $1
         13      > RETURN                                                       $1
   14    14*       VERIFY_RETURN_TYPE                                           
         15*     > RETURN                                                       null

End of function witha

Function withb:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XhG90
function name:  withB
number of ops:  16
compiled vars:  !0 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV                                                 !0      
   18     1        NEW                              self                $1      
          2        INIT_FCALL                                                   'get_defined_vars'
          3        DO_ICALL                                             $2      
          4        INIT_FCALL                                                   'get_object_vars'
          5        FETCH_THIS                                           ~3      
          6        SEND_VAL                                                     ~3
          7        DO_ICALL                                             $4      
          8        ADD                                                  ~5      $2, $4
          9        SEND_UNPACK                                                  ~5
         10        CHECK_UNDEF_ARGS                                             
         11        DO_FCALL                                          1          
         12        VERIFY_RETURN_TYPE                                           $1
         13      > RETURN                                                       $1
   19    14*       VERIFY_RETURN_TYPE                                           
         15*     > RETURN                                                       null

End of function withb

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
177.06 ms | 3362 KiB | 16 Q