3v4l.org

run code in 300+ 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 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jNFmL
function name:  __get
number of ops:  11
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'in_array'
          2        SEND_VAR                                                 !0
          3        FETCH_OBJ_R                                      ~1      'compat_fields'
          4        SEND_VAL                                                 ~1
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $2      
          7      > JMPZ                                                     $2, ->10
    9     8    >   FETCH_OBJ_R                                      ~3      !0
          9      > RETURN                                                   ~3
   11    10    > > RETURN                                                   null

End of function __get

Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jNFmL
function name:  __set
number of ops:  13
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        INIT_FCALL                                               'in_array'
          3        SEND_VAR                                                 !0
          4        FETCH_OBJ_R                                      ~2      'compat_fields'
          5        SEND_VAL                                                 ~2
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $3      
          8      > JMPZ                                                     $3, ->12
   15     9    >   ASSIGN_OBJ                                       ~4      !0
         10        OP_DATA                                                  !1
         11      > RETURN                                                   ~4
   17    12    > > RETURN                                                   null

End of function __set

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

End of function __isset

Function __unset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/jNFmL
function name:  __unset
number of ops:  10
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        INIT_FCALL                                               'in_array'
          2        SEND_VAR                                                 !0
          3        FETCH_OBJ_R                                      ~1      'compat_fields'
          4        SEND_VAL                                                 ~1
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $2      
          7      > JMPZ                                                     $2, ->9
   29     8    >   UNSET_OBJ                                                !0
   31     9    > > 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.0.0


preferences:
162.73 ms | 1475 KiB | 16 Q