3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $foo =2; } class Hydrator { public function getPrivate($obj, $attribute) { $getter = function(){return $obj->$attribute;}; return \Closure::bind($getter, $obj); } } $hydrated = new Hydrator(); $obj = new Foo(); var_dump($obj->foo); $getter = $hydrated->getPrivate($obj, 'foo'); var_dump($getter());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WZW7D
function name:  (null)
number of ops:  21
compiled vars:  !0 = $hydrated, !1 = $obj, !2 = $getter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $3      'Hydrator'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   16     3        NEW                                              $6      'Foo'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $6
   17     6        INIT_FCALL                                               'var_dump'
          7        FETCH_OBJ_R                                      ~9      !1, 'foo'
          8        SEND_VAL                                                 ~9
          9        DO_ICALL                                                 
   18    10        INIT_METHOD_CALL                                         !0, 'getPrivate'
         11        SEND_VAR_EX                                              !1
         12        SEND_VAL_EX                                              'foo'
         13        DO_FCALL                                      0  $11     
         14        ASSIGN                                                   !2, $11
   20    15        INIT_FCALL                                               'var_dump'
         16        INIT_DYNAMIC_CALL                                        !2
         17        DO_FCALL                                      0  $13     
         18        SEND_VAR                                                 $13
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FWZW7D%3A10%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WZW7D
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $obj, !1 = $attribute
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   FETCH_OBJ_R                                      ~2      !0, !1
          1      > RETURN                                                   ~2
          2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWZW7D%3A10%240

Class Foo: [no user functions]
Class Hydrator:
Function getprivate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WZW7D
function name:  getPrivate
number of ops:  10
compiled vars:  !0 = $obj, !1 = $attribute, !2 = $getter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWZW7D%3A10%240'
          3        ASSIGN                                                   !2, ~3
   11     4        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $5      
          8      > RETURN                                                   $5
   12     9*     > RETURN                                                   null

End of function getprivate

End of class Hydrator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
188.5 ms | 1400 KiB | 15 Q