3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sum = function ($a, $b) { return $a + $b; }; function calc($value_or_function) { static $buffer = []; if (is_callable($value_or_function)) { if (count($buffer) === 0) { throw new \InvalidArgumentException('Not enough parameters.'); } $result = array_reduce(array_slice($buffer, 1), static function ($result, $item) use ($value_or_function) { return $value_or_function($result, $item); }, $buffer[0]); $buffer = []; return $result; } $buffer[] = $value_or_function; return __FUNCTION__; } echo calc(5)(4)(3)($sum), PHP_EOL; echo calc(5)(2)(2)('pow');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rsqd1
function name:  (null)
number of ops:  30
compiled vars:  !0 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          1        ASSIGN                                                   !0, ~1
   23     2        INIT_FCALL                                               'calc'
          3        SEND_VAL                                                 5
          4        DO_FCALL                                      0  $3      
          5        INIT_DYNAMIC_CALL                                        $3
          6        SEND_VAL_EX                                              4
          7        DO_FCALL                                      0  $4      
          8        INIT_DYNAMIC_CALL                                        $4
          9        SEND_VAL_EX                                              3
         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'
   24    16        INIT_FCALL                                               'calc'
         17        SEND_VAL                                                 5
         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_VAL_EX                                              2
         24        DO_FCALL                                      0  $9      
         25        INIT_DYNAMIC_CALL                                        $9
         26        SEND_VAL_EX                                              'pow'
         27        DO_FCALL                                      0  $10     
         28        ECHO                                                     $10
         29      > 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/rsqd1
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ADD                                              ~2      !0, !1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of Dynamic Function 0

Function calc:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 28
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rsqd1
function name:  calc
number of ops:  32
compiled vars:  !0 = $value_or_function, !1 = $buffer, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        BIND_STATIC                                              !1
    8     2        INIT_FCALL                                               'is_callable'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5      > JMPZ                                                     $3, ->28
    9     6    >   COUNT                                            ~4      !1
          7        IS_IDENTICAL                                             ~4, 0
          8      > JMPZ                                                     ~5, ->13
   10     9    >   NEW                                              $6      'InvalidArgumentException'
         10        SEND_VAL_EX                                              'Not+enough+parameters.'
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $6
   12    13    >   INIT_FCALL                                               'array_reduce'
         14        INIT_FCALL                                               'array_slice'
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 1
         17        DO_ICALL                                         $8      
         18        SEND_VAR                                                 $8
         19        DECLARE_LAMBDA_FUNCTION                          ~9      [0]
         20        BIND_LEXICAL                                             ~9, !0
   14    21        SEND_VAL                                                 ~9
         22        FETCH_DIM_R                                      ~10     !1, 0
         23        SEND_VAL                                                 ~10
   12    24        DO_ICALL                                         $11     
         25        ASSIGN                                                   !2, $11
   15    26        ASSIGN                                                   !1, <array>
   16    27      > RETURN                                                   !2
   19    28    >   ASSIGN_DIM                                               !1
         29        OP_DATA                                                  !0
   20    30      > RETURN                                                   'calc'
   21    31*     > 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/rsqd1
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $result, !1 = $item, !2 = $value_or_function
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   13     3        INIT_DYNAMIC_CALL                                        !2
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
   14     8*     > RETURN                                                   null

End of Dynamic Function 0

End of function calc

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.7 ms | 1020 KiB | 18 Q