3v4l.org

run code in 500+ PHP versions simultaneously
<?php function foo(int $a) { var_dump($a); } function define_callbacks() { $string = 'foo'; $lambda = fn(...$args) => foo(...$args); $fcc = foo(...); return [$string, $lambda, $fcc]; } function test_callback($callback) { $callback(1); try { $callback(new class{}); } catch ( TypeError $e ) { echo $e->getMessage(), "\n"; } } [$string, $lambda, $fcc] = define_callbacks(); echo "== String-based ==\n"; test_callback($string); echo "\n== Type-less lambda ==\n"; test_callback($lambda); echo "\n== First-class callable ==\n"; test_callback($fcc);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q2H2Z
function name:  (null)
number of ops:  22
compiled vars:  !0 = $string, !1 = $lambda, !2 = $fcc
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                                   'define_callbacks'
          1        DO_FCALL                                          0  $3      
          2        FETCH_LIST_R                                         $4      $3, 0
          3        ASSIGN                                                       !0, $4
          4        FETCH_LIST_R                                         $6      $3, 1
          5        ASSIGN                                                       !1, $6
          6        FETCH_LIST_R                                         $8      $3, 2
          7        ASSIGN                                                       !2, $8
          8        FREE                                                         $3
   26     9        ECHO                                                         '%3D%3D+String-based+%3D%3D%0A'
   27    10        INIT_FCALL                                                   'test_callback'
         11        SEND_VAR                                                     !0
         12        DO_FCALL                                          0          
   29    13        ECHO                                                         '%0A%3D%3D+Type-less+lambda+%3D%3D%0A'
   30    14        INIT_FCALL                                                   'test_callback'
         15        SEND_VAR                                                     !1
         16        DO_FCALL                                          0          
   32    17        ECHO                                                         '%0A%3D%3D+First-class+callable+%3D%3D%0A'
   33    18        INIT_FCALL                                                   'test_callback'
         19        SEND_VAR                                                     !2
         20        DO_FCALL                                          0          
         21      > RETURN                                                       1

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q2H2Z
function name:  foo
number of ops:  5
compiled vars:  !0 = $a
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        INIT_FCALL                                                   'var_dump'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                                     
    5     4      > RETURN                                                       null

End of function foo

Function define_callbacks:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q2H2Z
function name:  define_callbacks
number of ops:  11
compiled vars:  !0 = $string, !1 = $lambda, !2 = $fcc
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                       !0, 'foo'
    9     1        DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          2        ASSIGN                                                       !1, ~4
   10     3        INIT_FCALL                                                   'foo'
          4        CALLABLE_CONVERT                                     ~6      
          5        ASSIGN                                                       !2, ~6
   12     6        INIT_ARRAY                                           ~8      !0
          7        ADD_ARRAY_ELEMENT                                    ~8      !1
          8        ADD_ARRAY_ELEMENT                                    ~8      !2
          9      > RETURN                                                       ~8
   13    10*     > 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/Q2H2Z
function name:  {closure:define_callbacks():9}
number of ops:  7
compiled vars:  !0 = $args
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV_VARIADIC                                        !0      
          1        INIT_FCALL                                                   'foo'
          2        SEND_UNPACK                                                  !0
          3        CHECK_UNDEF_ARGS                                             
          4        DO_FCALL                                          0  $1      
          5      > RETURN                                                       $1
          6*     > RETURN                                                       null

End of Dynamic Function 0

End of function define_callbacks

Function test_callback:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 11
Branch analysis from position: 11
2 jumps found. (Code = 107) Position 1 = 12, Position 2 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q2H2Z
function name:  test_callback
number of ops:  17
compiled vars:  !0 = $callback, !1 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
   16     1        INIT_DYNAMIC_CALL                                            !0
          2        SEND_VAL_EX                                                  1
          3        DO_FCALL                                          0          
   18     4        INIT_DYNAMIC_CALL                                            !0
          5        DECLARE_ANON_CLASS                                   <unknown> 
          6        NEW                                                  $4      $3
          7        DO_FCALL                                          0          
          8        SEND_VAR_NO_REF_EX                                           $4
          9        DO_FCALL                                          0          
         10      > JMP                                                          ->16
   19    11  E > > CATCH                                           last         'TypeError'
   20    12    >   INIT_METHOD_CALL                                             !1, 'getMessage'
         13        DO_FCALL                                          0  $7      
         14        ECHO                                                         $7
         15        ECHO                                                         '%0A'
   22    16    > > RETURN                                                       null

End of function test_callback

Class class@anonymous: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.94 ms | 1366 KiB | 20 Q