3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private $x; public function __construct($v) { $this->x = $v; } public function getIncrementor() { return function() { return ++$this->x; }; } } $a = new A(0); $b = new A(10); $ca = $a->getIncrementor(); $cb = $ca->bindTo($b); $cb2 = Closure::bind($ca, $b); var_dump($ca()); var_dump($cb()); var_dump($cb2());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DrT3I
function name:  (null)
number of ops:  36
compiled vars:  !0 = $a, !1 = $b, !2 = $ca, !3 = $cb, !4 = $cb2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   NEW                                              $5      'A'
          1        SEND_VAL_EX                                              0
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $5
   56     4        NEW                                              $8      'A'
          5        SEND_VAL_EX                                              10
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $8
   65     8        INIT_METHOD_CALL                                         !0, 'getIncrementor'
          9        DO_FCALL                                      0  $11     
         10        ASSIGN                                                   !2, $11
   69    11        INIT_METHOD_CALL                                         !2, 'bindTo'
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   73    15        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         16        SEND_VAR                                                 !2
         17        SEND_VAR                                                 !1
         18        DO_FCALL                                      0  $15     
         19        ASSIGN                                                   !4, $15
   82    20        INIT_FCALL                                               'var_dump'
         21        INIT_DYNAMIC_CALL                                        !2
         22        DO_FCALL                                      0  $17     
         23        SEND_VAR                                                 $17
         24        DO_ICALL                                                 
   86    25        INIT_FCALL                                               'var_dump'
         26        INIT_DYNAMIC_CALL                                        !3
         27        DO_FCALL                                      0  $19     
         28        SEND_VAR                                                 $19
         29        DO_ICALL                                                 
   90    30        INIT_FCALL                                               'var_dump'
         31        INIT_DYNAMIC_CALL                                        !4
         32        DO_FCALL                                      0  $21     
         33        SEND_VAR                                                 $21
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FDrT3I%3A35%240

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

End of function __construct

Function getincrementor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DrT3I
function name:  getIncrementor
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FDrT3I%3A35%240'
          1      > RETURN                                                   ~0
   39     2*     > RETURN                                                   null

End of function getincrementor

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.31 ms | 1400 KiB | 15 Q