3v4l.org

run code in 300+ PHP versions simultaneously
<?php // This is a basic class without any special behavior. No deprecation error occur despite the public_property being unset. $foo = new Foo(); $foo->public_property = true; unset( $foo->public_property ); $foo->public_property = true; // A class with a __set magic method that allows modifying declared public properties, mimicking the basic class behaviour and providing more backward compatibility. $baz = new Baz(); $baz->public_property = true; unset( $baz->public_property ); $baz->public_property = true; // This is a class with a __set magic method that restricts dynamic property creation. $bar = new Bar(); $bar->public_property = true; unset( $bar->public_property ); $bar->public_property = true; class Foo { public $public_property; } class Baz { public $public_property; public function __set( $prop, $value ) { if ( 'known_dynamic_property' === $prop ) { // Dynamic property-specific logic goes here. return; } // Checks if the property is a known public property and allows setting it. if ( 'public_property' === $prop ) { $this->public_property = $value; return; } trigger_error( sprintf( 'Setting the dynamic property "%s" on %s is deprecated', $prop, __CLASS__ ), E_USER_DEPRECATED ); } } class Bar { public $public_property; public function __set( $prop, $value ) { if ( 'known_dynamic_property' === $prop ) { // Dynamic property-specific logic goes here. return; } trigger_error( sprintf( 'Setting the dynamic property "%s" on %s is deprecated', $prop, __CLASS__ ), E_USER_DEPRECATED ); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QU0tT
function name:  (null)
number of ops:  25
compiled vars:  !0 = $foo, !1 = $baz, !2 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   NEW                                              $3      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
    5     3        ASSIGN_OBJ                                               !0, 'public_property'
          4        OP_DATA                                                  <true>
    6     5        UNSET_OBJ                                                !0, 'public_property'
    7     6        ASSIGN_OBJ                                               !0, 'public_property'
          7        OP_DATA                                                  <true>
   10     8        NEW                                              $8      'Baz'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $8
   11    11        ASSIGN_OBJ                                               !1, 'public_property'
         12        OP_DATA                                                  <true>
   12    13        UNSET_OBJ                                                !1, 'public_property'
   13    14        ASSIGN_OBJ                                               !1, 'public_property'
         15        OP_DATA                                                  <true>
   16    16        NEW                                              $13     'Bar'
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !2, $13
   17    19        ASSIGN_OBJ                                               !2, 'public_property'
         20        OP_DATA                                                  <true>
   18    21        UNSET_OBJ                                                !2, 'public_property'
   19    22        ASSIGN_OBJ                                               !2, 'public_property'
         23        OP_DATA                                                  <true>
   62    24      > RETURN                                                   1

Class Foo: [no user functions]
Class Baz:
Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QU0tT
function name:  __set
number of ops:  20
compiled vars:  !0 = $prop, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   30     2        IS_IDENTICAL                                             !0, 'known_dynamic_property'
          3      > JMPZ                                                     ~2, ->5
   32     4    > > RETURN                                                   null
   36     5    >   IS_IDENTICAL                                             !0, 'public_property'
          6      > JMPZ                                                     ~3, ->10
   37     7    >   ASSIGN_OBJ                                               'public_property'
          8        OP_DATA                                                  !1
   38     9      > RETURN                                                   null
   41    10    >   INIT_FCALL                                               'trigger_error'
   42    11        INIT_FCALL                                               'sprintf'
         12        SEND_VAL                                                 'Setting+the+dynamic+property+%22%25s%22+on+%25s+is+deprecated'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 'Baz'
         15        DO_ICALL                                         $5      
         16        SEND_VAR                                                 $5
   43    17        SEND_VAL                                                 16384
   41    18        DO_ICALL                                                 
   45    19      > RETURN                                                   null

End of function __set

End of class Baz.

Class Bar:
Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QU0tT
function name:  __set
number of ops:  15
compiled vars:  !0 = $prop, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   52     2        IS_IDENTICAL                                             !0, 'known_dynamic_property'
          3      > JMPZ                                                     ~2, ->5
   54     4    > > RETURN                                                   null
   57     5    >   INIT_FCALL                                               'trigger_error'
   58     6        INIT_FCALL                                               'sprintf'
          7        SEND_VAL                                                 'Setting+the+dynamic+property+%22%25s%22+on+%25s+is+deprecated'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 'Bar'
         10        DO_ICALL                                         $3      
         11        SEND_VAR                                                 $3
   59    12        SEND_VAL                                                 16384
   57    13        DO_ICALL                                                 
   61    14      > RETURN                                                   null

End of function __set

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.26 ms | 1465 KiB | 15 Q