3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { function hi() { return "hello"; } } // in global scope $f = function() { return $this->hi(); }; $a = new A(); $g = $f->bindTo($a); echo $g(), PHP_EOL; // works, no warnings class B extends A { // in a static function static function make() { return function() { return $this->hi(); // fatal error }; } } $h = B::make(); $i = $h->bindTo($a); // warning echo $i(), PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YMYeu
function name:  (null)
number of ops:  25
compiled vars:  !0 = $f, !1 = $a, !2 = $g, !3 = $h, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_LAMBDA_FUNCTION                          ~5      [0]
          1        ASSIGN                                                   !0, ~5
   13     2        NEW                                              $7      'A'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $7
   14     5        INIT_METHOD_CALL                                         !0, 'bindTo'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $10     
          8        ASSIGN                                                   !2, $10
   15     9        INIT_DYNAMIC_CALL                                        !2
         10        DO_FCALL                                      0  $12     
         11        ECHO                                                     $12
         12        ECHO                                                     '%0A'
   26    13        INIT_STATIC_METHOD_CALL                                  'B', 'make'
         14        DO_FCALL                                      0  $13     
         15        ASSIGN                                                   !3, $13
   27    16        INIT_METHOD_CALL                                         !3, 'bindTo'
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0  $15     
         19        ASSIGN                                                   !4, $15
   28    20        INIT_DYNAMIC_CALL                                        !4
         21        DO_FCALL                                      0  $17     
         22        ECHO                                                     $17
         23        ECHO                                                     '%0A'
         24      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YMYeu
function name:  {closure}
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   FETCH_THIS                                       $0      
          1        INIT_METHOD_CALL                                         $0, 'hi'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   12     4*     > RETURN                                                   null

End of Dynamic Function 0

Class A:
Function hi:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YMYeu
function name:  hi
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   'hello'
    6     1*     > RETURN                                                   null

End of function hi

End of class A.

Class B:
Function make:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YMYeu
function name:  make
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   DECLARE_LAMBDA_FUNCTION                          ~0      [0]
   22     1      > RETURN                                                   ~0
   23     2*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YMYeu
function name:  {closure}
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   FETCH_THIS                                       $0      
          1        INIT_METHOD_CALL                                         $0, 'hi'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   22     4*     > RETURN                                                   null

End of Dynamic Function 0

End of function make

Function hi:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YMYeu
function name:  hi
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   'hello'
    6     1*     > RETURN                                                   null

End of function hi

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
193.59 ms | 1000 KiB | 13 Q