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; }; } } class B { function __construct($val) { $this->val = $val; } } $ob1 = new A(1); $ob2 = new A(2); $ola = new B(3); $cl = $ob1->getClosure(); echo $cl(), "\n"; $cl = $cl->bindTo($ola); echo $cl(), "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/43gbL
function name:  (null)
number of ops:  28
compiled vars:  !0 = $ob1, !1 = $ob2, !2 = $ola, !3 = $cl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $4      'A'
          1        SEND_VAL_EX                                              1
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $4
   19     4        NEW                                              $7      'A'
          5        SEND_VAL_EX                                              2
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $7
   20     8        NEW                                              $10     'B'
          9        SEND_VAL_EX                                              3
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $10
   22    12        INIT_METHOD_CALL                                         !0, 'getClosure'
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   23    15        INIT_DYNAMIC_CALL                                        !3
         16        DO_FCALL                                      0  $15     
         17        ECHO                                                     $15
         18        ECHO                                                     '%0A'
   24    19        INIT_METHOD_CALL                                         !3, 'bindTo'
         20        SEND_VAR_EX                                              !2
         21        DO_FCALL                                      0  $16     
         22        ASSIGN                                                   !3, $16
   25    23        INIT_DYNAMIC_CALL                                        !3
         24        DO_FCALL                                      0  $18     
         25        ECHO                                                     $18
         26        ECHO                                                     '%0A'
         27      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F43gbL%3A8%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/43gbL
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%2F43gbL%3A8%240

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/43gbL
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/43gbL
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%2F43gbL%3A8%240'
          1      > RETURN                                                   ~0
    9     2*     > RETURN                                                   null

End of function getclosure

End of class A.

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

End of function __construct

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.05 ms | 944 KiB | 14 Q