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 "** Test `__get()` **\n"; echo "With magic methods: "; var_dump( $with_magic_methods->_prop ); echo "No magic methods: "; var_dump( $no_magic_methods->_prop ); echo "\n\n ** Test `__isset()` **\n"; echo "With magic methods: "; var_dump( isset( $with_magic_methods->_prop ) ); echo "No magic methods: "; var_dump( isset( $no_magic_methods->_prop ) ); echo "\n\n ** Test `__set()` **\n"; $new_value = array( 'test' ); $with_magic_methods->_prop = $new_value; $no_magic_methods->_prop = $new_value; echo "With magic methods: "; var_dump( $with_magic_methods->_prop ); echo "No magic methods: "; var_dump( $no_magic_methods->_prop ); echo "\n\n ** Test `__isset()` after an `__unset()` **\n"; unset( $with_magic_methods->_prop ); unset( $no_magic_methods->_prop ); echo "With magic methods:"; var_dump( isset( $with_magic_methods->_prop ) ); echo "No magic methods: "; var_dump( isset( $no_magic_methods->_prop ) ); echo "\n\n ** Test `__get()` after an __unset() **\n"; echo "With magic methods:"; var_dump( $with_magic_methods->_prop ); echo "No magic methods: "; var_dump( $no_magic_methods->_prop ); echo "\n\n ** Test `__set()` after an __unset() **\n"; $new_value = array( 'test after an unset' ); $with_magic_methods->_prop = $new_value; $no_magic_methods->_prop = $new_value; echo "With magic methods:"; var_dump( $with_magic_methods->_prop ); echo "No magic methods: "; var_dump( $no_magic_methods->_prop ); } run_test();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jNFmL
function name:  (null)
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   88     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/jNFmL
function name:  run_test
number of ops:  85
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                                                         '%2A%2A+Test+%60__get%28%29%60+%2A%2A%0A'
   43     7        ECHO                                                         'With+magic+methods%3A+'
   44     8        INIT_FCALL                                                   'var_dump'
          9        FETCH_OBJ_R                                          ~9      !0, '_prop'
         10        SEND_VAL                                                     ~9
         11        DO_ICALL                                                     
   45    12        ECHO                                                         'No+magic+methods%3A+'
   46    13        INIT_FCALL                                                   'var_dump'
         14        FETCH_OBJ_R                                          ~11     !1, '_prop'
         15        SEND_VAL                                                     ~11
         16        DO_ICALL                                                     
   48    17        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__isset%28%29%60+%2A%2A%0A'
   49    18        ECHO                                                         'With+magic+methods%3A+'
   50    19        INIT_FCALL                                                   'var_dump'
         20        ISSET_ISEMPTY_PROP_OBJ                               ~13     !0, '_prop'
         21        SEND_VAL                                                     ~13
         22        DO_ICALL                                                     
   51    23        ECHO                                                         'No+magic+methods%3A+'
   52    24        INIT_FCALL                                                   'var_dump'
         25        ISSET_ISEMPTY_PROP_OBJ                               ~15     !1, '_prop'
         26        SEND_VAL                                                     ~15
         27        DO_ICALL                                                     
   54    28        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__set%28%29%60+%2A%2A%0A'
   55    29        ASSIGN                                                       !2, <array>
   56    30        ASSIGN_OBJ                                                   !0, '_prop'
         31        OP_DATA                                                      !2
   57    32        ASSIGN_OBJ                                                   !1, '_prop'
         33        OP_DATA                                                      !2
   58    34        ECHO                                                         'With+magic+methods%3A+'
   59    35        INIT_FCALL                                                   'var_dump'
         36        FETCH_OBJ_R                                          ~20     !0, '_prop'
         37        SEND_VAL                                                     ~20
         38        DO_ICALL                                                     
   60    39        ECHO                                                         'No+magic+methods%3A+'
   61    40        INIT_FCALL                                                   'var_dump'
         41        FETCH_OBJ_R                                          ~22     !1, '_prop'
         42        SEND_VAL                                                     ~22
         43        DO_ICALL                                                     
   63    44        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__isset%28%29%60+after+an+%60__unset%28%29%60+%2A%2A%0A'
   64    45        UNSET_OBJ                                                    !0, '_prop'
   65    46        UNSET_OBJ                                                    !1, '_prop'
   67    47        ECHO                                                         'With+magic+methods%3A'
   68    48        INIT_FCALL                                                   'var_dump'
         49        ISSET_ISEMPTY_PROP_OBJ                               ~24     !0, '_prop'
         50        SEND_VAL                                                     ~24
         51        DO_ICALL                                                     
   69    52        ECHO                                                         'No+magic+methods%3A+'
   70    53        INIT_FCALL                                                   'var_dump'
         54        ISSET_ISEMPTY_PROP_OBJ                               ~26     !1, '_prop'
         55        SEND_VAL                                                     ~26
         56        DO_ICALL                                                     
   72    57        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__get%28%29%60+after+an+__unset%28%29+%2A%2A%0A'
   73    58        ECHO                                                         'With+magic+methods%3A'
   74    59        INIT_FCALL                                                   'var_dump'
         60        FETCH_OBJ_R                                          ~28     !0, '_prop'
         61        SEND_VAL                                                     ~28
         62        DO_ICALL                                                     
   75    63        ECHO                                                         'No+magic+methods%3A+'
   76    64        INIT_FCALL                                                   'var_dump'
         65        FETCH_OBJ_R                                          ~30     !1, '_prop'
         66        SEND_VAL                                                     ~30
         67        DO_ICALL                                                     
   78    68        ECHO                                                         '%0A%0A+%2A%2A+Test+%60__set%28%29%60+after+an+__unset%28%29+%2A%2A%0A'
   79    69        ASSIGN                                                       !2, <array>
   80    70        ASSIGN_OBJ                                                   !0, '_prop'
         71        OP_DATA                                                      !2
   81    72        ASSIGN_OBJ                                                   !1, '_prop'
         73        OP_DATA                                                      !2
   82    74        ECHO                                                         'With+magic+methods%3A'
   83    75        INIT_FCALL                                                   'var_dump'
         76        FETCH_OBJ_R                                          ~35     !0, '_prop'
         77        SEND_VAL                                                     ~35
         78        DO_ICALL                                                     
   84    79        ECHO                                                         'No+magic+methods%3A+'
   85    80        INIT_FCALL                                                   'var_dump'
         81        FETCH_OBJ_R                                          ~37     !1, '_prop'
         82        SEND_VAL                                                     ~37
         83        DO_ICALL                                                     
   86    84      > 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/jNFmL
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/jNFmL
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/jNFmL
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/jNFmL
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:
176.83 ms | 1615 KiB | 15 Q