3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private $name; public function __construct($name) { $this->name = $name; } } // test callable function getName() { return $this->name; } $bob = new A("Bob"); $cl1 = Closure::fromCallable("getName"); $cl1 = $cl1->bindTo($bob, 'A'); //This will retrieve: Uncaught Error: Cannot access private property A::$name $result = $cl1(); echo $result; //But for a Lambda function $cl2 = function() { return $this->name; }; $cl2 = $cl2->bindTo($bob, 'A'); $result = $cl2(); // This will print Bob echo $result;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tq0lO
function name:  (null)
number of ops:  29
compiled vars:  !0 = $bob, !1 = $cl1, !2 = $result, !3 = $cl2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   NEW                                              $4      'A'
          1        SEND_VAL_EX                                              'Bob'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $4
   18     4        INIT_STATIC_METHOD_CALL                                  'Closure', 'fromCallable'
          5        SEND_VAL                                                 'getName'
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !1, $7
   19     8        INIT_METHOD_CALL                                         !1, 'bindTo'
          9        SEND_VAR_EX                                              !0
         10        SEND_VAL_EX                                              'A'
         11        DO_FCALL                                      0  $9      
         12        ASSIGN                                                   !1, $9
   22    13        INIT_DYNAMIC_CALL                                        !1
         14        DO_FCALL                                      0  $11     
         15        ASSIGN                                                   !2, $11
   23    16        ECHO                                                     !2
   26    17        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ftq0lO%3A26%240'
         18        ASSIGN                                                   !3, ~13
   29    19        INIT_METHOD_CALL                                         !3, 'bindTo'
         20        SEND_VAR_EX                                              !0
         21        SEND_VAL_EX                                              'A'
         22        DO_FCALL                                      0  $15     
         23        ASSIGN                                                   !3, $15
   30    24        INIT_DYNAMIC_CALL                                        !3
         25        DO_FCALL                                      0  $17     
         26        ASSIGN                                                   !2, $17
   33    27        ECHO                                                     !2
         28      > RETURN                                                   1

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tq0lO
function name:  getName
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_THIS                                       $0      
          1        FETCH_OBJ_R                                      ~1      $0, 'name'
          2      > RETURN                                                   ~1
   15     3*     > RETURN                                                   null

End of function getname

Function %00%7Bclosure%7D%2Fin%2Ftq0lO%3A26%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tq0lO
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_THIS                                       $0      
          1        FETCH_OBJ_R                                      ~1      $0, 'name'
          2      > RETURN                                                   ~1
   28     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ftq0lO%3A26%240

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tq0lO
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
    8     3      > RETURN                                                   null

End of function __construct

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.54 ms | 1399 KiB | 13 Q