3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { function __construct($val) { $this->val = $val; } function getClosure() { //Возвращает замыкание, связанное с текущими объектом и областью видимости return function() { return $this->val; }; } } $ob1 = new A(1); $ob2 = new A(2); $cl = $ob1->getClosure(); echo $cl(), "\n"; $cl = $cl->bindTo($ob2); echo $cl(), "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4i40k
function name:  (null)
number of ops:  24
compiled vars:  !0 = $ob1, !1 = $ob2, !2 = $cl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   NEW                                              $3      'A'
          1        SEND_VAL_EX                                              1
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   13     4        NEW                                              $6      'A'
          5        SEND_VAL_EX                                              2
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $6
   15     8        INIT_METHOD_CALL                                         !0, 'getClosure'
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !2, $9
   16    11        INIT_DYNAMIC_CALL                                        !2
         12        DO_FCALL                                      0  $11     
         13        ECHO                                                     $11
         14        ECHO                                                     '%0A'
   17    15        INIT_METHOD_CALL                                         !2, 'bindTo'
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0  $12     
         18        ASSIGN                                                   !2, $12
   18    19        INIT_DYNAMIC_CALL                                        !2
         20        DO_FCALL                                      0  $14     
         21        ECHO                                                     $14
         22        ECHO                                                     '%0A'
         23      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2F4i40k%3A8%240

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

End of function __construct

Function getclosure:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4i40k
function name:  getClosure
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F4i40k%3A8%240'
          1      > RETURN                                                   ~0
    9     2*     > RETURN                                                   null

End of function getclosure

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.09 ms | 1399 KiB | 13 Q