3v4l.org

run code in 500+ PHP versions simultaneously
<?php class With_Magic_Methods { private $_prop = array(); protected $compat_fields = array( '_prop' ); public function __get( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { return $this->$name; } } public function __set( $name, $value ) { if ( in_array( $name, $this->compat_fields, true ) ) { return $this->$name = $value; } } public function __isset( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { return isset( $this->$name ); } return false; } public function __unset( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { unset( $this->$name ); } } } class No_Magic_Methods { public $_prop = array(); } function run_test() { $with_magic_methods = new With_Magic_Methods(); $no_magic_methods = new No_Magic_Methods(); echo "\n ***** TEST WITH A DYNAMIC PROPERTY ***** \n\n\n"; // __get() echo "** Test `__get()` **\n"; echo "With magic methods: "; var_dump( $with_magic_methods->_dynamic_property ); echo "No magic methods: "; var_dump( $no_magic_methods->_dynamic_property ); // __isset() echo "\n\n ** Test `__isset()` **\n"; echo "With magic methods: "; var_dump( isset( $with_magic_methods->_dynamic_property ) ); echo "No magic methods: "; var_dump( isset( $no_magic_methods->_dynamic_property ) ); // __set() echo "\n\n ** Test `__set()` **\n"; $new_value = array( 'test' ); $with_magic_methods->_dynamic_property = $new_value; $no_magic_methods->_dynamic_property = $new_value; echo "With magic methods: "; var_dump( $with_magic_methods->_dynamic_property ); echo "No magic methods: "; var_dump( $no_magic_methods->_dynamic_property ); // Unset. unset( $with_magic_methods->_dynamic_property ); unset( $no_magic_methods->_dynamic_property ); echo "\n\n ** Test `__isset()` after an `__unset()` **\n"; echo "With magic methods:"; var_dump( isset( $with_magic_methods->_dynamic_property ) ); echo "No magic methods: "; var_dump( isset( $no_magic_methods->_dynamic_property ) ); echo "\n\n ** Test `__get()` after an __unset() **\n"; echo "With magic methods:"; var_dump( $with_magic_methods->_dynamic_property ); echo "No magic methods: "; var_dump( $no_magic_methods->_dynamic_property ); echo "\n\n ** Test `__set()` after an __unset() **\n"; $new_value = array( 'test after an unset' ); $with_magic_methods->_dynamic_property = $new_value; $no_magic_methods->_dynamic_property = $new_value; echo "With magic methods:"; var_dump( $with_magic_methods->_dynamic_property ); echo "No magic methods: "; var_dump( $no_magic_methods->_dynamic_property ); } run_test();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nCACX
function name:  (null)
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   94     0  E >   INIT_FCALL                                                   'run_test'
          1        DO_FCALL                                          0          
          2      > RETURN                                                       1

Function run_test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nCACX
function name:  run_test
number of ops:  86
compiled vars:  !0 = $with_magic_methods, !1 = $no_magic_methods, !2 = $new_value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   39     0  E >   NEW                                                  $3      'With_Magic_Methods'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $3
   40     3        NEW                                                  $6      'No_Magic_Methods'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !1, $6
   42     6        ECHO                                                         '%0A+%2A%2A%2A%2A%2A+TEST+WITH+A+DYNAMIC+PROPERTY+%2A%2A%2A%2A%2A+%0A%0A%0A'
   45     7        ECHO                                                         '%2A%2A+Test+%60__get%28%29%60+%2A%2A%0A'
   46     8        ECHO                                                         'With+magic+methods%3A+'
   47     9        INIT_FCALL                                                   'var_dump'
         10        FETCH_OBJ_R                                          ~9      !0, '_dynamic_property'
         11        SEND_VAL                                                     ~9
         12        DO_ICALL                                                     
   48    13        ECHO                                                         'No+magic+methods%3A+'
   49    14        INIT_FCALL                                                   'var_dump'
         15        FETCH_OBJ_R                                          ~11     !1, '_dynamic_property'
         16        SEND_VAL                                                     ~11
         17        DO_ICALL                                                     
   52    18        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__isset%28%29%60+%2A%2A%0A'
   53    19        ECHO                                                         'With+magic+methods%3A+'
   54    20        INIT_FCALL                                                   'var_dump'
         21        ISSET_ISEMPTY_PROP_OBJ                               ~13     !0, '_dynamic_property'
         22        SEND_VAL                                                     ~13
         23        DO_ICALL                                                     
   55    24        ECHO                                                         'No+magic+methods%3A+'
   56    25        INIT_FCALL                                                   'var_dump'
         26        ISSET_ISEMPTY_PROP_OBJ                               ~15     !1, '_dynamic_property'
         27        SEND_VAL                                                     ~15
         28        DO_ICALL                                                     
   59    29        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__set%28%29%60+%2A%2A%0A'
   60    30        ASSIGN                                                       !2, <array>
   61    31        ASSIGN_OBJ                                                   !0, '_dynamic_property'
         32        OP_DATA                                                      !2
   62    33        ASSIGN_OBJ                                                   !1, '_dynamic_property'
         34        OP_DATA                                                      !2
   63    35        ECHO                                                         'With+magic+methods%3A+'
   64    36        INIT_FCALL                                                   'var_dump'
         37        FETCH_OBJ_R                                          ~20     !0, '_dynamic_property'
         38        SEND_VAL                                                     ~20
         39        DO_ICALL                                                     
   65    40        ECHO                                                         'No+magic+methods%3A+'
   66    41        INIT_FCALL                                                   'var_dump'
         42        FETCH_OBJ_R                                          ~22     !1, '_dynamic_property'
         43        SEND_VAL                                                     ~22
         44        DO_ICALL                                                     
   69    45        UNSET_OBJ                                                    !0, '_dynamic_property'
   70    46        UNSET_OBJ                                                    !1, '_dynamic_property'
   72    47        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__isset%28%29%60+after+an+%60__unset%28%29%60+%2A%2A%0A'
   73    48        ECHO                                                         'With+magic+methods%3A'
   74    49        INIT_FCALL                                                   'var_dump'
         50        ISSET_ISEMPTY_PROP_OBJ                               ~24     !0, '_dynamic_property'
         51        SEND_VAL                                                     ~24
         52        DO_ICALL                                                     
   75    53        ECHO                                                         'No+magic+methods%3A+'
   76    54        INIT_FCALL                                                   'var_dump'
         55        ISSET_ISEMPTY_PROP_OBJ                               ~26     !1, '_dynamic_property'
         56        SEND_VAL                                                     ~26
         57        DO_ICALL                                                     
   78    58        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__get%28%29%60+after+an+__unset%28%29+%2A%2A%0A'
   79    59        ECHO                                                         'With+magic+methods%3A'
   80    60        INIT_FCALL                                                   'var_dump'
         61        FETCH_OBJ_R                                          ~28     !0, '_dynamic_property'
         62        SEND_VAL                                                     ~28
         63        DO_ICALL                                                     
   81    64        ECHO                                                         'No+magic+methods%3A+'
   82    65        INIT_FCALL                                                   'var_dump'
         66        FETCH_OBJ_R                                          ~30     !1, '_dynamic_property'
         67        SEND_VAL                                                     ~30
         68        DO_ICALL                                                     
   84    69        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__set%28%29%60+after+an+__unset%28%29+%2A%2A%0A'
   85    70        ASSIGN                                                       !2, <array>
   86    71        ASSIGN_OBJ                                                   !0, '_dynamic_property'
         72        OP_DATA                                                      !2
   87    73        ASSIGN_OBJ                                                   !1, '_dynamic_property'
         74        OP_DATA                                                      !2
   88    75        ECHO                                                         'With+magic+methods%3A'
   89    76        INIT_FCALL                                                   'var_dump'
         77        FETCH_OBJ_R                                          ~35     !0, '_dynamic_property'
         78        SEND_VAL                                                     ~35
         79        DO_ICALL                                                     
   90    80        ECHO                                                         'No+magic+methods%3A+'
   91    81        INIT_FCALL                                                   'var_dump'
         82        FETCH_OBJ_R                                          ~37     !1, '_dynamic_property'
         83        SEND_VAL                                                     ~37
         84        DO_ICALL                                                     
   92    85      > RETURN                                                       null

End of function run_test

Class With_Magic_Methods:
Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nCACX
function name:  __get
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
    8     1        FETCH_OBJ_R                                          ~1      'compat_fields'
          2        FRAMELESS_ICALL_3                in_array            ~2      !0, ~1
          3        OP_DATA                                                      <true>
          4      > JMPZ                                                         ~2, ->7
    9     5    >   FETCH_OBJ_R                                          ~3      !0
          6      > RETURN                                                       ~3
   11     7    > > RETURN                                                       null

End of function __get

Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nCACX
function name:  __set
number of ops:  10
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   14     2        FETCH_OBJ_R                                          ~2      'compat_fields'
          3        FRAMELESS_ICALL_3                in_array            ~3      !0, ~2
          4        OP_DATA                                                      <true>
          5      > JMPZ                                                         ~3, ->9
   15     6    >   ASSIGN_OBJ                                           ~4      !0
          7        OP_DATA                                                      !1
          8      > RETURN                                                       ~4
   17     9    > > RETURN                                                       null

End of function __set

Function __isset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nCACX
function name:  __isset
number of ops:  9
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
   20     1        FETCH_OBJ_R                                          ~1      'compat_fields'
          2        FRAMELESS_ICALL_3                in_array            ~2      !0, ~1
          3        OP_DATA                                                      <true>
          4      > JMPZ                                                         ~2, ->7
   21     5    >   ISSET_ISEMPTY_PROP_OBJ                               ~3      !0
          6      > RETURN                                                       ~3
   24     7    > > RETURN                                                       <false>
   25     8*     > RETURN                                                       null

End of function __isset

Function __unset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/nCACX
function name:  __unset
number of ops:  7
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   27     0  E >   RECV                                                 !0      
   28     1        FETCH_OBJ_R                                          ~1      'compat_fields'
          2        FRAMELESS_ICALL_3                in_array            ~2      !0, ~1
          3        OP_DATA                                                      <true>
          4      > JMPZ                                                         ~2, ->6
   29     5    >   UNSET_OBJ                                                    !0
   31     6    > > RETURN                                                       null

End of function __unset

End of class With_Magic_Methods.

Class No_Magic_Methods: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
180.77 ms | 3778 KiB | 15 Q