3v4l.org

run code in 500+ PHP versions simultaneously
<?php class demo { public $n = 0; function __construct() { $this->n =& $this->n; } function magic() { if ($this->n) return; } function set($n) { $this->n = $n; } } // Outputs 1 = 1 as expected $a1 = new demo(); $b1 = clone $a1; $a1->magic(); $b1->set(1); echo "{$a1->n} = {$b1->n}\n"; // Outputs 0 = 1 (magic() method is called a little earlier) $a2 = new demo(); $a2->magic(); $b2 = clone $a2; $b2->set(1); echo "{$a2->n} = {$b2->n}\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VTJMI
function name:  (null)
number of ops:  35
compiled vars:  !0 = $a1, !1 = $b1, !2 = $a2, !3 = $b2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   NEW                                                  $4      'demo'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $4
   14     3        CLONE                                                ~7      !0
          4        ASSIGN                                                       !1, ~7
   15     5        INIT_METHOD_CALL                                             !0, 'magic'
          6        DO_FCALL                                          0          
   16     7        INIT_METHOD_CALL                                             !1, 'set'
          8        SEND_VAL_EX                                                  1
          9        DO_FCALL                                          0          
   17    10        FETCH_OBJ_R                                          ~11     !0, 'n'
         11        ROPE_INIT                                         4  ~14     ~11
         12        ROPE_ADD                                          1  ~14     ~14, '+%3D+'
         13        FETCH_OBJ_R                                          ~12     !1, 'n'
         14        ROPE_ADD                                          2  ~14     ~14, ~12
         15        ROPE_END                                          3  ~13     ~14, '%0A'
         16        ECHO                                                         ~13
   20    17        NEW                                                  $16     'demo'
         18        DO_FCALL                                          0          
         19        ASSIGN                                                       !2, $16
   21    20        INIT_METHOD_CALL                                             !2, 'magic'
         21        DO_FCALL                                          0          
   22    22        CLONE                                                ~20     !2
         23        ASSIGN                                                       !3, ~20
   23    24        INIT_METHOD_CALL                                             !3, 'set'
         25        SEND_VAL_EX                                                  1
         26        DO_FCALL                                          0          
   24    27        FETCH_OBJ_R                                          ~23     !2, 'n'
         28        ROPE_INIT                                         4  ~26     ~23
         29        ROPE_ADD                                          1  ~26     ~26, '+%3D+'
         30        FETCH_OBJ_R                                          ~24     !3, 'n'
         31        ROPE_ADD                                          2  ~26     ~26, ~24
         32        ROPE_END                                          3  ~25     ~26, '%0A'
         33        ECHO                                                         ~25
         34      > RETURN                                                       1

Class demo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VTJMI
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   FETCH_OBJ_W                                          $1      'n'
          1        MAKE_REF                                             $2      $1
          2        ASSIGN_OBJ_REF                                               'n'
          3        OP_DATA                                                      $2
          4      > RETURN                                                       null

End of function __construct

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

End of function magic

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

End of function set

End of class demo.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
174.69 ms | 3339 KiB | 13 Q