3v4l.org

run code in 300+ PHP versions simultaneously
<?php function calc($x) { return function($y = null) use ($x) { if (is_callable($y)) { return $y(...$x); } else { $args = (array) $x; $args[] = $y; return calc($args); } }; } $sum = function(...$args) { return array_sum($args); }; echo calc(5)(3)(2)($sum), PHP_EOL; echo calc(1)(2)($sum), PHP_EOL; echo calc(2)(3)('pow'), PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r0emm
function name:  (null)
number of ops:  39
compiled vars:  !0 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          1        ASSIGN                                                   !0, ~1
   18     2        INIT_FCALL                                               'calc'
          3        SEND_VAL                                                 5
          4        DO_FCALL                                      0  $3      
          5        INIT_DYNAMIC_CALL                                        $3
          6        SEND_VAL_EX                                              3
          7        DO_FCALL                                      0  $4      
          8        INIT_DYNAMIC_CALL                                        $4
          9        SEND_VAL_EX                                              2
         10        DO_FCALL                                      0  $5      
         11        INIT_DYNAMIC_CALL                                        $5
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $6      
         14        ECHO                                                     $6
         15        ECHO                                                     '%0A'
   19    16        INIT_FCALL                                               'calc'
         17        SEND_VAL                                                 1
         18        DO_FCALL                                      0  $7      
         19        INIT_DYNAMIC_CALL                                        $7
         20        SEND_VAL_EX                                              2
         21        DO_FCALL                                      0  $8      
         22        INIT_DYNAMIC_CALL                                        $8
         23        SEND_VAR_EX                                              !0
         24        DO_FCALL                                      0  $9      
         25        ECHO                                                     $9
         26        ECHO                                                     '%0A'
   20    27        INIT_FCALL                                               'calc'
         28        SEND_VAL                                                 2
         29        DO_FCALL                                      0  $10     
         30        INIT_DYNAMIC_CALL                                        $10
         31        SEND_VAL_EX                                              3
         32        DO_FCALL                                      0  $11     
         33        INIT_DYNAMIC_CALL                                        $11
         34        SEND_VAL_EX                                              'pow'
         35        DO_FCALL                                      0  $12     
         36        ECHO                                                     $12
         37        ECHO                                                     '%0A'
   21    38      > 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/r0emm
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV_VARIADIC                                    !0      
          1        INIT_FCALL                                               'array_sum'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
          5*     > RETURN                                                   null

End of Dynamic Function 0

Function calc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r0emm
function name:  calc
number of ops:  5
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          2        BIND_LEXICAL                                             ~1, !0
   13     3      > RETURN                                                   ~1
   14     4*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r0emm
function name:  {closure}
number of ops:  21
compiled vars:  !0 = $y, !1 = $x, !2 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV_INIT                                        !0      null
          1        BIND_STATIC                                              !1
    6     2        INIT_FCALL                                               'is_callable'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5      > JMPZ                                                     $3, ->12
    7     6    >   INIT_DYNAMIC_CALL                                        !0
          7        SEND_UNPACK                                              !1
          8        CHECK_UNDEF_ARGS                                         
          9        DO_FCALL                                      1  $4      
         10      > RETURN                                                   $4
    6    11*       JMP                                                      ->20
    9    12    >   CAST                                          7  ~5      !1
         13        ASSIGN                                                   !2, ~5
   10    14        ASSIGN_DIM                                               !2
         15        OP_DATA                                                  !0
   11    16        INIT_FCALL_BY_NAME                                       'calc'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0  $8      
         19      > RETURN                                                   $8
   13    20*     > RETURN                                                   null

End of Dynamic Function 0

End of function calc

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.6 ms | 1019 KiB | 18 Q