3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $bar = 'A'; public function withNewBar($bar) { $obj = clone($this); $obj->bar = $bar; return $obj; } public function changeBarOnANewFoo($bar) { $obj = new Foo(); $obj->bar = $bar; return $obj; } public function changeBarOnAnotherFoo(Foo $obj, $bar) { $obj->bar = $bar; } public function bar() { return $this->bar; } } $one = new Foo(); $two = $one->withNewBar('B'); $three = $one->changeBarOnANewFoo('C'); $four = new Foo(); $one->changeBarOnAnotherFoo($four, 'D'); var_dump($one->bar() === 'A' ); var_dump($two->bar() === 'B' ); var_dump($three->bar() === 'C' ); var_dump($four->bar() === 'D' );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FGJo8
function name:  (null)
number of ops:  43
compiled vars:  !0 = $one, !1 = $two, !2 = $three, !3 = $four
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   NEW                                              $4      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   33     3        INIT_METHOD_CALL                                         !0, 'withNewBar'
          4        SEND_VAL_EX                                              'B'
          5        DO_FCALL                                      0  $7      
          6        ASSIGN                                                   !1, $7
   34     7        INIT_METHOD_CALL                                         !0, 'changeBarOnANewFoo'
          8        SEND_VAL_EX                                              'C'
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !2, $9
   35    11        NEW                                              $11     'Foo'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !3, $11
   36    14        INIT_METHOD_CALL                                         !0, 'changeBarOnAnotherFoo'
         15        SEND_VAR_EX                                              !3
         16        SEND_VAL_EX                                              'D'
         17        DO_FCALL                                      0          
   38    18        INIT_FCALL                                               'var_dump'
         19        INIT_METHOD_CALL                                         !0, 'bar'
         20        DO_FCALL                                      0  $15     
         21        IS_IDENTICAL                                     ~16     $15, 'A'
         22        SEND_VAL                                                 ~16
         23        DO_ICALL                                                 
   39    24        INIT_FCALL                                               'var_dump'
         25        INIT_METHOD_CALL                                         !1, 'bar'
         26        DO_FCALL                                      0  $18     
         27        IS_IDENTICAL                                     ~19     $18, 'B'
         28        SEND_VAL                                                 ~19
         29        DO_ICALL                                                 
   40    30        INIT_FCALL                                               'var_dump'
         31        INIT_METHOD_CALL                                         !2, 'bar'
         32        DO_FCALL                                      0  $21     
         33        IS_IDENTICAL                                     ~22     $21, 'C'
         34        SEND_VAL                                                 ~22
         35        DO_ICALL                                                 
   41    36        INIT_FCALL                                               'var_dump'
         37        INIT_METHOD_CALL                                         !3, 'bar'
         38        DO_FCALL                                      0  $24     
         39        IS_IDENTICAL                                     ~25     $24, 'D'
         40        SEND_VAL                                                 ~25
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Class Foo:
Function withnewbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FGJo8
function name:  withNewBar
number of ops:  8
compiled vars:  !0 = $bar, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        FETCH_THIS                                       ~2      
          2        CLONE                                            ~3      ~2
          3        ASSIGN                                                   !1, ~3
   10     4        ASSIGN_OBJ                                               !1, 'bar'
          5        OP_DATA                                                  !0
   11     6      > RETURN                                                   !1
   12     7*     > RETURN                                                   null

End of function withnewbar

Function changebaronanewfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FGJo8
function name:  changeBarOnANewFoo
number of ops:  8
compiled vars:  !0 = $bar, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        NEW                                              $2      'Foo'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
   17     4        ASSIGN_OBJ                                               !1, 'bar'
          5        OP_DATA                                                  !0
   18     6      > RETURN                                                   !1
   19     7*     > RETURN                                                   null

End of function changebaronanewfoo

Function changebaronanotherfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FGJo8
function name:  changeBarOnAnotherFoo
number of ops:  5
compiled vars:  !0 = $obj, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        ASSIGN_OBJ                                               !0, 'bar'
          3        OP_DATA                                                  !1
   24     4      > RETURN                                                   null

End of function changebaronanotherfoo

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

End of function bar

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.04 ms | 1400 KiB | 15 Q