3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { function Foo($name) { // create a reference inside the global array $globalref global $globalref;//<--- variável global WTF que tenta exemplicar a diferença //do new e do &= $globalref[] = &$this; // set name to passed value $this->setName($name); // and put it out $this->echoName(); } function echoName() { echo "<br />", $this->name; } function setName($name) { $this->name = $name; } } // now we will change the name. what do you expect? // you could expect that both $bar1 and $globalref[0] change their names... $bar1->setName('set from outside'); // as mentioned before this is not the case. $bar1->echoName(); $globalref[0]->echoName(); /* output: set from outside set in constructor */ // let us see what is different with $bar2 and $globalref[1] $bar2->setName('set from outside'); // luckily they are not only equal, they are the same variable // thus $bar2->name and $globalref[1]->name are the same too $bar2->echoName(); $globalref[1]->echoName(); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cCL24
function name:  (null)
number of ops:  17
compiled vars:  !0 = $bar1, !1 = $globalref, !2 = $bar2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_METHOD_CALL                                         !0, 'setName'
          1        SEND_VAL_EX                                              'set+from+outside'
          2        DO_FCALL                                      0          
   29     3        INIT_METHOD_CALL                                         !0, 'echoName'
          4        DO_FCALL                                      0          
   30     5        FETCH_DIM_R                                      ~5      !1, 0
          6        INIT_METHOD_CALL                                         ~5, 'echoName'
          7        DO_FCALL                                      0          
   37     8        INIT_METHOD_CALL                                         !2, 'setName'
          9        SEND_VAL_EX                                              'set+from+outside'
         10        DO_FCALL                                      0          
   41    11        INIT_METHOD_CALL                                         !2, 'echoName'
         12        DO_FCALL                                      0          
   42    13        FETCH_DIM_R                                      ~9      !1, 1
         14        INIT_METHOD_CALL                                         ~9, 'echoName'
         15        DO_FCALL                                      0          
   44    16      > RETURN                                                   1

Class Foo:
Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cCL24
function name:  Foo
number of ops:  12
compiled vars:  !0 = $name, !1 = $globalref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        BIND_GLOBAL                                              !1, 'globalref'
    7     2        FETCH_THIS                                       $3      
          3        MAKE_REF                                         $4      $3
          4        FETCH_DIM_W                                      $2      !1
          5        ASSIGN_REF                                               $2, $4
    9     6        INIT_METHOD_CALL                                         'setName'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   11     9        INIT_METHOD_CALL                                         'echoName'
         10        DO_FCALL                                      0          
   12    11      > RETURN                                                   null

End of function foo

Function echoname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cCL24
function name:  echoName
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ECHO                                                     '%3Cbr+%2F%3E'
          1        FETCH_OBJ_R                                      ~0      'name'
          2        ECHO                                                     ~0
   16     3      > RETURN                                                   null

End of function echoname

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

End of function setname

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.3 ms | 1399 KiB | 13 Q