3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test(callable $fn){ $curried = function(...$currArgs) use(&$fn, &$curried){ $reflection = new ReflectionFunction($fn); $args = count($reflection->getParameters()); if(count($currArgs) == $args){ return $fn(...$currArgs); }else{ return function(...$currArgs2) use( $fn, $currArgs, &$curried){ return $curried(...array_merge($currArgs, $currArgs2)); }; } }; return $curried; } $c = test(fn($x, $y, $z) => $x + $y + $z); echo $c(10)(20,30),"\n"; echo $c(10,20)(30),"\n"; echo $c(10,20,30),"\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/82aE5
function name:  (null)
number of ops:  31
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'test'
          1        DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          2        SEND_VAL                                                 ~1
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   26     5        INIT_DYNAMIC_CALL                                        !0
          6        SEND_VAL_EX                                              10
          7        DO_FCALL                                      0  $4      
          8        INIT_DYNAMIC_CALL                                        $4
          9        SEND_VAL_EX                                              20
         10        SEND_VAL_EX                                              30
         11        DO_FCALL                                      0  $5      
         12        ECHO                                                     $5
         13        ECHO                                                     '%0A'
   27    14        INIT_DYNAMIC_CALL                                        !0
         15        SEND_VAL_EX                                              10
         16        SEND_VAL_EX                                              20
         17        DO_FCALL                                      0  $6      
         18        INIT_DYNAMIC_CALL                                        $6
         19        SEND_VAL_EX                                              30
         20        DO_FCALL                                      0  $7      
         21        ECHO                                                     $7
         22        ECHO                                                     '%0A'
   28    23        INIT_DYNAMIC_CALL                                        !0
         24        SEND_VAL_EX                                              10
         25        SEND_VAL_EX                                              20
         26        SEND_VAL_EX                                              30
         27        DO_FCALL                                      0  $8      
         28        ECHO                                                     $8
         29        ECHO                                                     '%0A'
         30      > 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/82aE5
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $x, !1 = $y, !2 = $z
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        ADD                                              ~3      !0, !1
          4        ADD                                              ~4      ~3, !2
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of Dynamic Function 0

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/82aE5
function name:  test
number of ops:  7
compiled vars:  !0 = $fn, !1 = $curried
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          2        BIND_LEXICAL                                             ~2, !0
          3        BIND_LEXICAL                                             ~2, !1
          4        ASSIGN                                                   !1, ~2
   20     5      > RETURN                                                   !1
   21     6*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/82aE5
function name:  {closure}
number of ops:  26
compiled vars:  !0 = $currArgs, !1 = $fn, !2 = $curried, !3 = $reflection, !4 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV_VARIADIC                                    !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
    8     3        NEW                                              $5      'ReflectionFunction'
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !3, $5
    9     7        INIT_METHOD_CALL                                         !3, 'getParameters'
          8        DO_FCALL                                      0  $8      
          9        COUNT                                            ~9      $8
         10        ASSIGN                                                   !4, ~9
   11    11        COUNT                                            ~11     !0
         12        IS_EQUAL                                                 !4, ~11
         13      > JMPZ                                                     ~12, ->20
   12    14    >   INIT_DYNAMIC_CALL                                        !1
         15        SEND_UNPACK                                              !0
         16        CHECK_UNDEF_ARGS                                         
         17        DO_FCALL                                      1  $13     
         18      > RETURN                                                   $13
   11    19*       JMP                                                      ->25
   14    20    >   DECLARE_LAMBDA_FUNCTION                          ~14     [0]
         21        BIND_LEXICAL                                             ~14, !1
         22        BIND_LEXICAL                                             ~14, !0
         23        BIND_LEXICAL                                             ~14, !2
   16    24      > RETURN                                                   ~14
   18    25*     > 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/82aE5
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $currArgs2, !1 = $fn, !2 = $currArgs, !3 = $curried
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV_VARIADIC                                    !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
   15     4        INIT_DYNAMIC_CALL                                        !3
          5        INIT_FCALL                                               'array_merge'
          6        SEND_VAR                                                 !2
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $4      
          9        SEND_UNPACK                                              $4
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      1  $5      
         12      > RETURN                                                   $5
   16    13*     > RETURN                                                   null

End of Dynamic Function 0

End of Dynamic Function 0

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.44 ms | 1456 KiB | 15 Q