3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $foo = 'foo'; protected $bar = 'bar'; } class FooProxy extends Foo { private $wrapped; // ... private static $publicProperties = array('foo' => true); public function __construct(Foo $wrapped) { $this->wrapped = $wrapped; } public function & __get($name) { if (isset(self::$publicProperties[$name])) { return $this->wrapped->$name; } return PublicAccessEmulator::get($this->wrapped, $name); } } class PublicAccessEmulator { public static function & get($object, $name) { return $object->$name; } } $foo = new FooProxy(new Foo()); var_dump($foo->foo); var_dump($foo->bar);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PuWls
function name:  (null)
number of ops:  15
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   NEW                                              $1      'FooProxy'
          1        NEW                                              $2      'Foo'
          2        DO_FCALL                                      0          
          3        SEND_VAR_NO_REF_EX                                       $2
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   43     6        INIT_FCALL                                               'var_dump'
          7        FETCH_OBJ_R                                      ~6      !0, 'foo'
          8        SEND_VAL                                                 ~6
          9        DO_ICALL                                                 
   44    10        INIT_FCALL                                               'var_dump'
         11        FETCH_OBJ_R                                      ~8      !0, 'bar'
         12        SEND_VAL                                                 ~8
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Class Foo: [no user functions]
Class FooProxy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PuWls
function name:  __construct
number of ops:  4
compiled vars:  !0 = $wrapped
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        ASSIGN_OBJ                                               'wrapped'
          2        OP_DATA                                                  !0
   20     3      > RETURN                                                   null

End of function __construct

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
Return found
Branch analysis from position: 7
Return found
filename:       /in/PuWls
function name:  __get
number of ops:  15
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        FETCH_STATIC_PROP_IS                             ~1      'publicProperties'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
   26     4    >   FETCH_OBJ_W                                      $3      'wrapped'
          5        FETCH_OBJ_W                                      $4      $3, !0
          6      > RETURN_BY_REF                                            $4
   29     7    >   INIT_STATIC_METHOD_CALL                                  'PublicAccessEmulator', 'get'
          8        CHECK_FUNC_ARG                                           
          9        FETCH_OBJ_FUNC_ARG                               $5      'wrapped'
         10        SEND_FUNC_ARG                                            $5
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $6      
         13      > RETURN_BY_REF                                            $6
   30    14*     > RETURN_BY_REF                                            null

End of function __get

End of class FooProxy.

Class PublicAccessEmulator:
Function get:
Finding entry points
Branch analysis from position: 0
Return found
filename:       /in/PuWls
function name:  get
number of ops:  5
compiled vars:  !0 = $object, !1 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   37     2        FETCH_OBJ_W                                      $2      !0, !1
          3      > RETURN_BY_REF                                            $2
   38     4*     > RETURN_BY_REF                                            null

End of function get

End of class PublicAccessEmulator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.57 ms | 1405 KiB | 15 Q