3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Thing { private string $state; public function __construct() { $this->state = 'foo'; } public function __set(string $property, $value) : void { if ((\debug_backtrace()[1]['object'] ?? null) !== $this) { throw new \Exception('nope'); } $this->$property = $value; } } $thing = new Thing(); var_dump($thing); $thing->state = 'this should never be allowed';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RiOcF
function name:  (null)
number of ops:  9
compiled vars:  !0 = $thing
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                                              $1      'Thing'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   22     3        INIT_FCALL                                               'var_dump'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   24     6        ASSIGN_OBJ                                               !0, 'state'
          7        OP_DATA                                                  'this+should+never+be+allowed'
          8      > RETURN                                                   1

Class Thing:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RiOcF
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN_OBJ                                               'state'
          1        OP_DATA                                                  'foo'
    9     2      > RETURN                                                   null

End of function __construct

Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RiOcF
function name:  __set
number of ops:  18
compiled vars:  !0 = $property, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        INIT_FCALL                                               'debug_backtrace'
          3        DO_ICALL                                         $2      
          4        FETCH_DIM_IS                                     ~3      $2, 1
          5        FETCH_DIM_IS                                     ~4      ~3, 'object'
          6        COALESCE                                         ~5      ~4
          7        QM_ASSIGN                                        ~5      null
          8        FETCH_THIS                                       ~6      
          9        IS_NOT_IDENTICAL                                         ~5, ~6
         10      > JMPZ                                                     ~7, ->15
   13    11    >   NEW                                              $8      'Exception'
         12        SEND_VAL_EX                                              'nope'
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $8
   16    15    >   ASSIGN_OBJ                                               !0
         16        OP_DATA                                                  !1
   17    17      > RETURN                                                   null

End of function __set

End of class Thing.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.15 ms | 1012 KiB | 15 Q