3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sum = function ($a, $b) { return $a + $b; }; function calc($value_or_function, array $buffer = []) { if (is_callable($value_or_function)) { if (count($buffer) === 0) { throw new \InvalidArgumentException('Not enough parameters.'); } return array_reduce(array_slice($buffer, 1), $value_or_function, $buffer[0]); } return static function ($otherValue) use ($buffer, $value_or_function) { return calc($otherValue, array_merge($buffer, [$value_or_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/AoKJO
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
   18     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'
   19    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/AoKJO
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 = 24
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: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AoKJO
function name:  calc
number of ops:  29
compiled vars:  !0 = $value_or_function, !1 = $buffer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    6     2        INIT_FCALL                                               'is_callable'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5      > JMPZ                                                     $2, ->24
    7     6    >   COUNT                                            ~3      !1
          7        IS_IDENTICAL                                             ~3, 0
          8      > JMPZ                                                     ~4, ->13
    8     9    >   NEW                                              $5      'InvalidArgumentException'
         10        SEND_VAL_EX                                              'Not+enough+parameters.'
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $5
   10    13    >   INIT_FCALL                                               'array_reduce'
         14        INIT_FCALL                                               'array_slice'
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 1
         17        DO_ICALL                                         $7      
         18        SEND_VAR                                                 $7
         19        SEND_VAR                                                 !0
         20        FETCH_DIM_R                                      ~8      !1, 0
         21        SEND_VAL                                                 ~8
         22        DO_ICALL                                         $9      
         23      > RETURN                                                   $9
   13    24    >   DECLARE_LAMBDA_FUNCTION                          ~10     [0]
         25        BIND_LEXICAL                                             ~10, !1
         26        BIND_LEXICAL                                             ~10, !0
   15    27      > RETURN                                                   ~10
   16    28*     > 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/AoKJO
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $otherValue, !1 = $buffer, !2 = $value_or_function
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   14     3        INIT_FCALL_BY_NAME                                       'calc'
          4        SEND_VAR_EX                                              !0
          5        INIT_FCALL                                               'array_merge'
          6        SEND_VAR                                                 !1
          7        INIT_ARRAY                                       ~3      !2
          8        SEND_VAL                                                 ~3
          9        DO_ICALL                                         $4      
         10        SEND_VAR_NO_REF_EX                                       $4
         11        DO_FCALL                                      0  $5      
         12      > RETURN                                                   $5
   15    13*     > RETURN                                                   null

End of Dynamic Function 0

End of function calc

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.9 ms | 1025 KiB | 19 Q