3v4l.org

run code in 300+ PHP versions simultaneously
<?php function &readPrivate($object, $k, $context = null) { $closure = function & () use ($k) { return $this->$k; }; $binding = Closure::bind( $closure, $object, $context); $value = & $binding->__invoke(); return $value; } class B { private $x = 'xb'; public $z = 'zb'; } class C { private $x = 'xc'; private $y = 'yc'; public $z = 'zc'; } $c = new C; var_dump(readPrivate($c, 'x', $c)); # var_dump(readPrivate($c, 'x', B::class));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4tAqu
function name:  (null)
number of ops:  12
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   NEW                                              $1      'C'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   34     3        INIT_FCALL                                               'var_dump'
          4        INIT_FCALL                                               'readprivate'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 'x'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $4      
          9        SEND_VAR                                                 $4
         10        DO_ICALL                                                 
   35    11      > RETURN                                                   1

Function readprivate:
Finding entry points
Branch analysis from position: 0
Return found
filename:       /in/4tAqu
function name:  readPrivate
number of ops:  17
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        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
          4        BIND_LEXICAL                                             ~6, !1
          5        ASSIGN                                                   !3, ~6
    9     6        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
   10     7        SEND_VAR                                                 !3
   11     8        SEND_VAR                                                 !0
   12     9        SEND_VAR                                                 !2
    9    10        DO_FCALL                                      0  $8      
         11        ASSIGN                                                   !4, $8
   14    12        INIT_METHOD_CALL                                         !4, '__invoke'
         13        DO_FCALL                                      0  $10     
         14        ASSIGN_REF                                               !5, $10
   16    15      > RETURN_BY_REF                                            !5
   17    16*     > RETURN_BY_REF                                            null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
Return found
filename:       /in/4tAqu
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   BIND_STATIC                                              !0
    6     1        FETCH_THIS                                       $1      
          2        FETCH_OBJ_W                                      $2      $1, !0
          3      > RETURN_BY_REF                                            $2
    7     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:
151.36 ms | 1013 KiB | 15 Q