3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Allows value objects to expose their properties while maintaining immutability. * * Define your properties in the docblock for your class with {@code @property}. */ class Value { private $a; public function __construct($a) { $this->a = $a; } public function __get($aProperty) { if (property_exists($this, $aProperty)) { return $this->{$aProperty}; } $this->triggerError("Undefined property: %s::$%s", $aProperty); } public function __set($aProperty, $aValue) { if (property_exists($this, $aProperty)) { $this->triggerError("Cannot access private property %s::$%s", $aProperty); } $this->triggerError("Undefined property: %s::$%s", $aProperty); } private function triggerError($message, $aProperty) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); throw new ErrorException(sprintf($message, __CLASS__, $aProperty), 0, E_USER_NOTICE, $backtrace[2]['file'], $backtrace[2]['line']); } } $v = new Value(1); var_dump($v->a); var_dump($v->b); $v->a = 3; $v->b = 4;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TIQNE
function name:  (null)
number of ops:  17
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   NEW                                              $1      'Value'
          1        SEND_VAL_EX                                              1
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   38     4        INIT_FCALL                                               'var_dump'
          5        FETCH_OBJ_R                                      ~4      !0, 'a'
          6        SEND_VAL                                                 ~4
          7        DO_ICALL                                                 
   39     8        INIT_FCALL                                               'var_dump'
          9        FETCH_OBJ_R                                      ~6      !0, 'b'
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                                 
   40    12        ASSIGN_OBJ                                               !0, 'a'
         13        OP_DATA                                                  3
   41    14        ASSIGN_OBJ                                               !0, 'b'
         15        OP_DATA                                                  4
         16      > RETURN                                                   1

Class Value:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TIQNE
function name:  __construct
number of ops:  4
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               'a'
          2        OP_DATA                                                  !0
   14     3      > RETURN                                                   null

End of function __construct

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TIQNE
function name:  __get
number of ops:  14
compiled vars:  !0 = $aProperty
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'property_exists'
          2        FETCH_THIS                                       ~1      
          3        SEND_VAL                                                 ~1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->9
   18     7    >   FETCH_OBJ_R                                      ~3      !0
          8      > RETURN                                                   ~3
   20     9    >   INIT_METHOD_CALL                                         'triggerError'
         10        SEND_VAL_EX                                              'Undefined+property%3A+%25s%3A%3A%24%25s'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
   21    13      > RETURN                                                   null

End of function __get

Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/TIQNE
function name:  __set
number of ops:  17
compiled vars:  !0 = $aProperty, !1 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   24     2        INIT_FCALL                                               'property_exists'
          3        FETCH_THIS                                       ~2      
          4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7      > JMPZ                                                     $3, ->12
   25     8    >   INIT_METHOD_CALL                                         'triggerError'
          9        SEND_VAL_EX                                              'Cannot+access+private+property+%25s%3A%3A%24%25s'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0          
   27    12    >   INIT_METHOD_CALL                                         'triggerError'
         13        SEND_VAL_EX                                              'Undefined+property%3A+%25s%3A%3A%24%25s'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0          
   28    16      > RETURN                                                   null

End of function __set

Function triggererror:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/TIQNE
function name:  triggerError
number of ops:  26
compiled vars:  !0 = $message, !1 = $aProperty, !2 = $backtrace
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   31     2        INIT_FCALL                                               'debug_backtrace'
          3        SEND_VAL                                                 2
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !2, $3
   32     6        NEW                                              $5      'ErrorException'
          7        INIT_FCALL                                               'sprintf'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 'Value'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $6      
         12        SEND_VAR_NO_REF_EX                                       $6
         13        SEND_VAL_EX                                              0
         14        SEND_VAL_EX                                              1024
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $7      !2, 2
         17        FETCH_DIM_FUNC_ARG                               $8      $7, 'file'
         18        SEND_FUNC_ARG                                            $8
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $9      !2, 2
         21        FETCH_DIM_FUNC_ARG                               $10     $9, 'line'
         22        SEND_FUNC_ARG                                            $10
         23        DO_FCALL                                      0          
         24      > THROW                                         0          $5
   33    25*     > RETURN                                                   null

End of function triggererror

End of class Value.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.43 ms | 1022 KiB | 17 Q