3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @property stdClass $x * @property stdClass $y */ class C { private $buffer = array(); function __get($key) { if (array_key_exists($key, $this->buffer)) { return $this->buffer[$key]; } $f = 'calc_' . $key; return $this->buffer[$key] = $this->$f(); } function calc_x() {print __METHOD__ . "\n"; $x = new stdClass; $x->y = $this->__get('y'); return $x; } function calc_y() {print __METHOD__ . "\n"; $y = new stdClass; // Set a stub to avoid infinite recursion. $this->buffer['y'] = $y; $y->x = $this->__get('x'); return $y; } } $c = new C; $x = $c->x; $y = $c->y; var_dump($x->y === $y, $y->x === $x); print "\n"; $c = new C; $y = $c->y; $x = $c->x; var_dump($x->y === $y, $y->x === $x);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nb3VF
function name:  (null)
number of ops:  32
compiled vars:  !0 = $c, !1 = $x, !2 = $y
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  33     0  E >   NEW                                              $3      :59
         1        DO_FCALL                                      0          
         2        QM_ASSIGN                                                !0
  34     3        FETCH_OBJ_R                                      ~6      !0, 'x'
         4        QM_ASSIGN                                                !1
  35     5        FETCH_OBJ_R                                      ~8      !0, 'y'
         6        QM_ASSIGN                                                !2
  36     7        INIT_FCALL                                               'var_dump'
         8        FETCH_OBJ_R                                      ~10     !1, 'y'
         9        IS_NOT_IDENTICAL                                 ~11     !2, ~10
        10        SEND_VAL                                                 ~11
        11        FETCH_OBJ_R                                      ~12     !2, 'x'
        12        IS_NOT_IDENTICAL                                 ~13     !1, ~12
        13        SEND_VAL                                                 ~13
        14        DO_ICALL                                                 
  38    15        ASSIGN_OBJ                                               '%0A'
  39    16        NEW                                              $15     :35
        17        DO_FCALL                                      0          
        18        QM_ASSIGN                                                !0
  40    19        FETCH_OBJ_R                                      ~18     !0, 'y'
        20        QM_ASSIGN                                                !2
  41    21        FETCH_OBJ_R                                      ~20     !0, 'x'
        22        QM_ASSIGN                                                !1
  42    23        INIT_FCALL                                               'var_dump'
        24        FETCH_OBJ_R                                      ~22     !1, 'y'
        25        IS_NOT_IDENTICAL                                 ~23     !2, ~22
        26        SEND_VAL                                                 ~23
        27        FETCH_OBJ_R                                      ~24     !2, 'x'
        28        IS_NOT_IDENTICAL                                 ~25     !1, ~24
        29        SEND_VAL                                                 ~25
        30        DO_ICALL                                                 
        31      > RETURN                                                   1

Class C:
Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nb3VF
function name:  __get
number of ops:  16
compiled vars:  !0 = $key, !1 = $f
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  10     0  E >   RECV                                             !0      
  11     1        FETCH_OBJ_R                                      ~2      'buffer'
         2        FUNC_NUM_ARGS                                    ~3      !0, ~2
         3      > JMPZ                                                     ~3, ->7
  12     4    >   FETCH_OBJ_R                                      ~4      'buffer'
         5        FETCH_DIM_R                                      ~5      ~4, !0
         6      > RETURN                                                   ~5
  14     7    >   CONCAT                                           ~6      'calc_', !0
         8        QM_ASSIGN                                                !1
  15     9        INIT_METHOD_CALL                                         !1
        10        DO_FCALL                                      0  $10     
        11        FETCH_OBJ_W                                      $8      'buffer'
        12        ASSIGN_ADD                                    0  $9      $8, !0
        13        OP_DATA                                                  $10
        14      > RETURN                                                   $9
  16    15*     > RETURN                                                   null

End of function __get

Function calc_x:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nb3VF
function name:  calc_x
number of ops:  11
compiled vars:  !0 = $x
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  18     0  E >   ASSIGN_OBJ                                               'C%3A%3Acalc_x%0A'
  19     1        NEW                                              $1      :16
         2        DO_FCALL                                      0          
         3        QM_ASSIGN                                                !0
  20     4        INIT_METHOD_CALL                                         '__get'
         5        SEND_VAL_EX                                              'y'
         6        DO_FCALL                                      0  $5      
         7        ASSIGN_SUB                                    8          !0, 'y'
         8        OP_DATA                                                  $5
  21     9      > RETURN                                                   !0
  22    10*     > RETURN                                                   null

End of function calc_x

Function calc_y:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nb3VF
function name:  calc_y
number of ops:  14
compiled vars:  !0 = $y
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  24     0  E >   ASSIGN_OBJ                                               'C%3A%3Acalc_y%0A'
  25     1        NEW                                              $1      :22
         2        DO_FCALL                                      0          
         3        QM_ASSIGN                                                !0
  27     4        FETCH_OBJ_W                                      $4      'buffer'
         5        ASSIGN_ADD                                    0          $4, 'y'
         6        OP_DATA                                                  !0
  28     7        INIT_METHOD_CALL                                         '__get'
         8        SEND_VAL_EX                                              'x'
         9        DO_FCALL                                      0  $7      
        10        ASSIGN_SUB                                   32          !0, 'x'
        11        OP_DATA                                                  $7
  29    12      > RETURN                                                   !0
  30    13*     > RETURN                                                   null

End of function calc_y

End of class C.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
13.29 ms | 416 KiB | 7 Q