3v4l.org

run code in 500+ 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; $v = $this->$f(); if (array_key_exists($key, $this->buffer)) { return $this->buffer[$key]; } return $this->buffer[$key] = $v; } 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/nXTYJ
function name:  (null)
number of ops:  32
compiled vars:  !0 = $c, !1 = $x, !2 = $y
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   NEW                                                  $3      'C'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $3
   38     3        FETCH_OBJ_R                                          ~6      !0, 'x'
          4        ASSIGN                                                       !1, ~6
   39     5        FETCH_OBJ_R                                          ~8      !0, 'y'
          6        ASSIGN                                                       !2, ~8
   40     7        INIT_FCALL                                                   'var_dump'
          8        FETCH_OBJ_R                                          ~10     !1, 'y'
          9        IS_IDENTICAL                                         ~11     !2, ~10
         10        SEND_VAL                                                     ~11
         11        FETCH_OBJ_R                                          ~12     !2, 'x'
         12        IS_IDENTICAL                                         ~13     !1, ~12
         13        SEND_VAL                                                     ~13
         14        DO_ICALL                                                     
   42    15        ECHO                                                         '%0A'
   43    16        NEW                                                  $15     'C'
         17        DO_FCALL                                          0          
         18        ASSIGN                                                       !0, $15
   44    19        FETCH_OBJ_R                                          ~18     !0, 'y'
         20        ASSIGN                                                       !2, ~18
   45    21        FETCH_OBJ_R                                          ~20     !0, 'x'
         22        ASSIGN                                                       !1, ~20
   46    23        INIT_FCALL                                                   'var_dump'
         24        FETCH_OBJ_R                                          ~22     !1, 'y'
         25        IS_IDENTICAL                                         ~23     !2, ~22
         26        SEND_VAL                                                     ~23
         27        FETCH_OBJ_R                                          ~24     !2, 'x'
         28        IS_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
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nXTYJ
function name:  __get
number of ops:  23
compiled vars:  !0 = $key, !1 = $f, !2 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
   11     1        FETCH_OBJ_R                                          ~3      'buffer'
          2        ARRAY_KEY_EXISTS                                             !0, ~3
          3      > JMPZ                                                         ~4, ->7
   12     4    >   FETCH_OBJ_R                                          ~5      'buffer'
          5        FETCH_DIM_R                                          ~6      ~5, !0
          6      > RETURN                                                       ~6
   14     7    >   CONCAT                                               ~7      'calc_', !0
          8        ASSIGN                                                       !1, ~7
   15     9        INIT_METHOD_CALL                                             !1
         10        DO_FCALL                                          0  $9      
         11        ASSIGN                                                       !2, $9
   16    12        FETCH_OBJ_R                                          ~11     'buffer'
         13        ARRAY_KEY_EXISTS                                             !0, ~11
         14      > JMPZ                                                         ~12, ->18
   17    15    >   FETCH_OBJ_R                                          ~13     'buffer'
         16        FETCH_DIM_R                                          ~14     ~13, !0
         17      > RETURN                                                       ~14
   19    18    >   FETCH_OBJ_W                                          $15     'buffer'
         19        ASSIGN_DIM                                           ~16     $15, !0
         20        OP_DATA                                                      !2
         21      > RETURN                                                       ~16
   20    22*     > 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/nXTYJ
function name:  calc_x
number of ops:  11
compiled vars:  !0 = $x
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   ECHO                                                         'C%3A%3Acalc_x%0A'
   23     1        NEW                                                  $1      'stdClass'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $1
   24     4        INIT_METHOD_CALL                                             '__get'
          5        SEND_VAL_EX                                                  'y'
          6        DO_FCALL                                          0  $5      
          7        ASSIGN_OBJ                                                   !0, 'y'
          8        OP_DATA                                                      $5
   25     9      > RETURN                                                       !0
   26    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/nXTYJ
function name:  calc_y
number of ops:  14
compiled vars:  !0 = $y
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   ECHO                                                         'C%3A%3Acalc_y%0A'
   29     1        NEW                                                  $1      'stdClass'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $1
   31     4        FETCH_OBJ_W                                          $4      'buffer'
          5        ASSIGN_DIM                                                   $4, 'y'
          6        OP_DATA                                                      !0
   32     7        INIT_METHOD_CALL                                             '__get'
          8        SEND_VAL_EX                                                  'x'
          9        DO_FCALL                                          0  $7      
         10        ASSIGN_OBJ                                                   !0, 'x'
         11        OP_DATA                                                      $7
   33    12      > RETURN                                                       !0
   34    13*     > RETURN                                                       null

End of function calc_y

End of class C.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.95 ms | 2306 KiB | 14 Q