3v4l.org

run code in 300+ PHP versions simultaneously
<?php function &readPrivate($object, $k, $context = null) { if (null === $context) { $context = $object; } $closure = function & () use ($k) { return $this->$k; }; $binding = Closure::bind( $closure, $object, $context); $value = & $binding->__invoke(); return $value; } class B { private $xb = 'xb_b'; private $x = 'xb'; public $z = 'zb'; } class C extends B { private $x = 'xc'; private $y = 'yc'; public $z = 'zc'; } $c = new C; var_dump(readPrivate($c, 'x')); var_dump(readPrivate($c, 'x', B::class)); var_dump(readPrivate($c, 'x', ReflectionClass::class));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2BZRg
function name:  (null)
number of ops:  27
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   NEW                                              $1      'C'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   39     3        INIT_FCALL                                               'var_dump'
          4        INIT_FCALL                                               'readprivate'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 'x'
          7        DO_FCALL                                      0  $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                                 
   40    10        INIT_FCALL                                               'var_dump'
         11        INIT_FCALL                                               'readprivate'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 'x'
         14        SEND_VAL                                                 'B'
         15        DO_FCALL                                      0  $6      
         16        SEND_VAR                                                 $6
         17        DO_ICALL                                                 
   41    18        INIT_FCALL                                               'var_dump'
         19        INIT_FCALL                                               'readprivate'
         20        SEND_VAR                                                 !0
         21        SEND_VAL                                                 'x'
         22        SEND_VAL                                                 'ReflectionClass'
         23        DO_FCALL                                      0  $8      
         24        SEND_VAR                                                 $8
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Function readprivate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
Return found
Branch analysis from position: 6
filename:       /in/2BZRg
function name:  readPrivate
number of ops:  20
compiled vars:  !0 = $object, !1 = $k, !2 = $context, !3 = $closure, !4 = $binding, !5 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
    5     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~6, ->6
    6     5    >   ASSIGN                                                   !2, !0
    9     6    >   DECLARE_LAMBDA_FUNCTION                          ~8      [0]
          7        BIND_LEXICAL                                             ~8, !1
          8        ASSIGN                                                   !3, ~8
   13     9        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
   14    10        SEND_VAR                                                 !3
   15    11        SEND_VAR                                                 !0
   16    12        SEND_VAR                                                 !2
   13    13        DO_FCALL                                      0  $10     
         14        ASSIGN                                                   !4, $10
   18    15        INIT_METHOD_CALL                                         !4, '__invoke'
         16        DO_FCALL                                      0  $12     
         17        ASSIGN_REF                                               !5, $12
   20    18      > RETURN_BY_REF                                            !5
   21    19*     > RETURN_BY_REF                                            null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
Return found
filename:       /in/2BZRg
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   BIND_STATIC                                              !0
   10     1        FETCH_THIS                                       $1      
          2        FETCH_OBJ_W                                      $2      $1, !0
          3      > RETURN_BY_REF                                            $2
   11     4*     > RETURN_BY_REF                                            null

End of Dynamic Function 0

End of function readprivate

Class B: [no user functions]
Class C: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.52 ms | 1017 KiB | 17 Q