3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $a = 1; } function deprivatise($obj, $callback) { $thief = function($obj) { call_user_func($callback, $obj); }; $objTheif = Closure::bind($thief, null, $obj); return $objTheif($obj); } $bar = new Foo; echo deprivatise($bar, function($ths) { return $ths->a; }) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1FDF7
function name:  (null)
number of ops:  11
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   19     3        INIT_FCALL                                               'deprivatise'
          4        SEND_VAR                                                 !0
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1FDF7%3A19%241'
   21     6        SEND_VAL                                                 ~4
          7        DO_FCALL                                      0  $5      
          8        CONCAT                                           ~6      $5, '%0A'
          9        ECHO                                                     ~6
         10      > RETURN                                                   1

Function deprivatise:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1FDF7
function name:  deprivatise
number of ops:  15
compiled vars:  !0 = $obj, !1 = $callback, !2 = $thief, !3 = $objTheif
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%2F1FDF7%3A10%240'
          3        ASSIGN                                                   !2, ~4
   13     4        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          5        SEND_VAR                                                 !2
          6        SEND_VAL                                                 null
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !3, $6
   14    10        INIT_DYNAMIC_CALL                                        !3
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $8      
         13      > RETURN                                                   $8
   15    14*     > RETURN                                                   null

End of function deprivatise

Function %00%7Bclosure%7D%2Fin%2F1FDF7%3A10%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1FDF7
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $obj, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        INIT_USER_CALL                                1          'call_user_func', !1
          2        SEND_USER                                                !0
          3        DO_FCALL                                      0          
   12     4      > RETURN                                                   null

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

Function %00%7Bclosure%7D%2Fin%2F1FDF7%3A19%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1FDF7
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $ths
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        FETCH_OBJ_R                                      ~1      !0, 'a'
          2      > RETURN                                                   ~1
   21     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1FDF7%3A19%241

Class Foo: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.52 ms | 1402 KiB | 14 Q