3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PropertyTest { /** Location for overloaded data. */ private $data = array(); /** Overloading not used on declared properties. */ public $declared = 1; /** Overloading only used on this when accessed outside the class. */ private $hidden = 2; public function __set($name, $value) { echo "Setting '$name' to '$value'\n"; $this->data[$name] = $value; } public function __get($name) { echo "Getting '$name'\n"; if (array_key_exists($name, $this->data)) { return $this->data[$name]; } $trace = debug_backtrace(); trigger_error( 'Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); return null; } /** As of PHP 5.1.0 */ public function __isset($name) { echo "Is '$name' set?\n"; return isset($this->data[$name]); } /** As of PHP 5.1.0 */ public function __unset($name) { echo "Unsetting '$name'\n"; unset($this->data[$name]); } /** Not a magic method, just here for example. */ public function getHidden() { return $this->hidden; } } echo "<pre>\n"; $obj = new PropertyTest; $obj->a = 1; echo $obj->a . "\n\n"; var_dump(isset($obj->a)); unset($obj->a); var_dump(isset($obj->a)); echo "\n"; echo $obj->declared . "\n\n"; echo "Let's experiment with the private property named 'hidden':\n"; echo "Privates are visible inside the class, so __get() not used...\n"; echo $obj->getHidden() . "\n"; echo "Privates not visible outside of class, so __get() is used...\n"; echo $obj->hidden . "\n"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FjgP9
function name:  (null)
number of ops:  33
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   ECHO                                                     '%3Cpre%3E%0A'
   59     1        NEW                                              $1      'PropertyTest'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   61     4        ASSIGN_OBJ                                               !0, 'a'
          5        OP_DATA                                                  1
   62     6        FETCH_OBJ_R                                      ~5      !0, 'a'
          7        CONCAT                                           ~6      ~5, '%0A%0A'
          8        ECHO                                                     ~6
   64     9        INIT_FCALL                                               'var_dump'
         10        ISSET_ISEMPTY_PROP_OBJ                           ~7      !0, 'a'
         11        SEND_VAL                                                 ~7
         12        DO_ICALL                                                 
   65    13        UNSET_OBJ                                                !0, 'a'
   66    14        INIT_FCALL                                               'var_dump'
         15        ISSET_ISEMPTY_PROP_OBJ                           ~9      !0, 'a'
         16        SEND_VAL                                                 ~9
         17        DO_ICALL                                                 
   67    18        ECHO                                                     '%0A'
   69    19        FETCH_OBJ_R                                      ~11     !0, 'declared'
         20        CONCAT                                           ~12     ~11, '%0A%0A'
         21        ECHO                                                     ~12
   71    22        ECHO                                                     'Let%27s+experiment+with+the+private+property+named+%27hidden%27%3A%0A'
   72    23        ECHO                                                     'Privates+are+visible+inside+the+class%2C+so+__get%28%29+not+used...%0A'
   73    24        INIT_METHOD_CALL                                         !0, 'getHidden'
         25        DO_FCALL                                      0  $13     
         26        CONCAT                                           ~14     $13, '%0A'
         27        ECHO                                                     ~14
   74    28        ECHO                                                     'Privates+not+visible+outside+of+class%2C+so+__get%28%29+is+used...%0A'
   75    29        FETCH_OBJ_R                                      ~15     !0, 'hidden'
         30        CONCAT                                           ~16     ~15, '%0A'
         31        ECHO                                                     ~16
   76    32      > RETURN                                                   1

Class PropertyTest:
Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FjgP9
function name:  __set
number of ops:  12
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        ROPE_INIT                                     5  ~3      'Setting+%27'
          3        ROPE_ADD                                      1  ~3      ~3, !0
          4        ROPE_ADD                                      2  ~3      ~3, '%27+to+%27'
          5        ROPE_ADD                                      3  ~3      ~3, !1
          6        ROPE_END                                      4  ~2      ~3, '%27%0A'
          7        ECHO                                                     ~2
   16     8        FETCH_OBJ_W                                      $6      'data'
          9        ASSIGN_DIM                                               $6, !0
         10        OP_DATA                                                  !1
   17    11      > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FjgP9
function name:  __get
number of ops:  29
compiled vars:  !0 = $name, !1 = $trace
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        ROPE_INIT                                     3  ~3      'Getting+%27'
          2        ROPE_ADD                                      1  ~3      ~3, !0
          3        ROPE_END                                      2  ~2      ~3, '%27%0A'
          4        ECHO                                                     ~2
   22     5        FETCH_OBJ_R                                      ~5      'data'
          6        ARRAY_KEY_EXISTS                                         !0, ~5
          7      > JMPZ                                                     ~6, ->11
   23     8    >   FETCH_OBJ_R                                      ~7      'data'
          9        FETCH_DIM_R                                      ~8      ~7, !0
         10      > RETURN                                                   ~8
   26    11    >   INIT_FCALL                                               'debug_backtrace'
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !1, $9
   27    14        INIT_FCALL                                               'trigger_error'
   28    15        CONCAT                                           ~11     'Undefined+property+via+__get%28%29%3A+', !0
   29    16        CONCAT                                           ~12     ~11, '+in+'
         17        FETCH_DIM_R                                      ~13     !1, 0
         18        FETCH_DIM_R                                      ~14     ~13, 'file'
         19        CONCAT                                           ~15     ~12, ~14
   30    20        CONCAT                                           ~16     ~15, '+on+line+'
         21        FETCH_DIM_R                                      ~17     !1, 0
         22        FETCH_DIM_R                                      ~18     ~17, 'line'
         23        CONCAT                                           ~19     ~16, ~18
         24        SEND_VAL                                                 ~19
   31    25        SEND_VAL                                                 1024
         26        DO_ICALL                                                 
   32    27      > RETURN                                                   null
   33    28*     > RETURN                                                   null

End of function __get

Function __isset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FjgP9
function name:  __isset
number of ops:  9
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        ROPE_INIT                                     3  ~2      'Is+%27'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%27+set%3F%0A'
          4        ECHO                                                     ~1
   39     5        FETCH_OBJ_IS                                     ~4      'data'
          6        ISSET_ISEMPTY_DIM_OBJ                         0  ~5      ~4, !0
          7      > RETURN                                                   ~5
   40     8*     > RETURN                                                   null

End of function __isset

Function __unset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FjgP9
function name:  __unset
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   45     1        ROPE_INIT                                     3  ~2      'Unsetting+%27'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%27%0A'
          4        ECHO                                                     ~1
   46     5        FETCH_OBJ_UNSET                                  $4      'data'
          6        UNSET_DIM                                                $4, !0
   47     7      > RETURN                                                   null

End of function __unset

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

End of function gethidden

End of class PropertyTest.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.03 ms | 1404 KiB | 19 Q