3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Placeholder{} function curry(callable $func, ... $curriedArgs) { return function(...$fulfillment) use ($func, $curriedArgs) { return $func(...array_merge(array_map(function($arg) use ($fulfillment) { if ($arg instanceof Placeholder) return array_shift($fulfillment); return $arg; }, $curriedArgs), $fulfillment)); }; }; $resultset = json_decode('[{ "id": 1, "gender": "Male", "name": "Matthew" }, { "id": 2, "gender": "Male", "name": "Willie" }, { "id": 3, "gender": "Female", "name": "Ann" }, { "id": 4, "gender": "Female", "name": "Margaret" }, { "id": 5, "gender": "Female", "name": "Marie" }]',TRUE); $filterGender = function($row,$gender){ return $row['gender']==$gender; }; $detectMen = curry($filterGender,(new Placeholder),'Male'); $detectWomen = curry($filterGender,(new Placeholder),'Female'); var_dump($detectMen(['gender'=>'Male'])); //works $getLadies = curry('array_filter',(new Placeholder),$detectWomen); var_dump($getLadies($resultset)); //does not work
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0i5FV
function name:  (null)
number of ops:  44
compiled vars:  !0 = $resultset, !1 = $filterGender, !2 = $detectMen, !3 = $detectWomen, !4 = $getLadies
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%5B%7B%0A++%22id%22%3A+1%2C%0A++%22gender%22%3A+%22Male%22%2C%0A++%22name%22%3A+%22Matthew%22%0A%7D%2C+%7B%0A++%22id%22%3A+2%2C%0A++%22gender%22%3A+%22Male%22%2C%0A++%22name%22%3A+%22Willie%22%0A%7D%2C+%7B%0A++%22id%22%3A+3%2C%0A++%22gender%22%3A+%22Female%22%2C%0A++%22name%22%3A+%22Ann%22%0A%7D%2C+%7B%0A++%22id%22%3A+4%2C%0A++%22gender%22%3A+%22Female%22%2C%0A++%22name%22%3A+%22Margaret%22%0A%7D%2C+%7B%0A++%22id%22%3A+5%2C%0A++%22gender%22%3A+%22Female%22%2C%0A++%22name%22%3A+%22Marie%22%0A%7D%5D'
   33     2        SEND_VAL                                                 <true>
   13     3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !0, $5
   35     5        DECLARE_LAMBDA_FUNCTION                          ~7      [0]
          6        ASSIGN                                                   !1, ~7
   39     7        INIT_FCALL                                               'curry'
          8        SEND_VAR                                                 !1
          9        NEW                                              $9      'Placeholder'
         10        DO_FCALL                                      0          
         11        SEND_VAR                                                 $9
         12        SEND_VAL                                                 'Male'
         13        DO_FCALL                                      0  $11     
         14        ASSIGN                                                   !2, $11
   40    15        INIT_FCALL                                               'curry'
         16        SEND_VAR                                                 !1
         17        NEW                                              $13     'Placeholder'
         18        DO_FCALL                                      0          
         19        SEND_VAR                                                 $13
         20        SEND_VAL                                                 'Female'
         21        DO_FCALL                                      0  $15     
         22        ASSIGN                                                   !3, $15
   42    23        INIT_FCALL                                               'var_dump'
         24        INIT_DYNAMIC_CALL                                        !2
         25        SEND_VAL_EX                                              <array>
         26        DO_FCALL                                      0  $17     
         27        SEND_VAR                                                 $17
         28        DO_ICALL                                                 
   44    29        INIT_FCALL                                               'curry'
         30        SEND_VAL                                                 'array_filter'
         31        NEW                                              $19     'Placeholder'
         32        DO_FCALL                                      0          
         33        SEND_VAR                                                 $19
         34        SEND_VAR                                                 !3
         35        DO_FCALL                                      0  $21     
         36        ASSIGN                                                   !4, $21
   46    37        INIT_FCALL                                               'var_dump'
         38        INIT_DYNAMIC_CALL                                        !4
         39        SEND_VAR_EX                                              !0
         40        DO_FCALL                                      0  $23     
         41        SEND_VAR                                                 $23
         42        DO_ICALL                                                 
         43      > 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/0i5FV
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $row, !1 = $gender
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   36     2        FETCH_DIM_R                                      ~2      !0, 'gender'
          3        IS_EQUAL                                         ~3      !1, ~2
          4      > RETURN                                                   ~3
   37     5*     > RETURN                                                   null

End of Dynamic Function 0

Function curry:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0i5FV
function name:  curry
number of ops:  7
compiled vars:  !0 = $func, !1 = $curriedArgs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_VARIADIC                                    !1      
    4     2        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          3        BIND_LEXICAL                                             ~2, !0
          4        BIND_LEXICAL                                             ~2, !1
   10     5      > RETURN                                                   ~2
   11     6*     > 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/0i5FV
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $fulfillment, !1 = $func, !2 = $curriedArgs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV_VARIADIC                                    !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
    5     3        INIT_DYNAMIC_CALL                                        !1
          4        INIT_FCALL                                               'array_merge'
          5        INIT_FCALL                                               'array_map'
          6        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          7        BIND_LEXICAL                                             ~3, !0
    9     8        SEND_VAL                                                 ~3
          9        SEND_VAR                                                 !2
    5    10        DO_ICALL                                         $4      
    9    11        SEND_VAR                                                 $4
         12        SEND_VAR                                                 !0
    5    13        DO_ICALL                                         $5      
    9    14        SEND_UNPACK                                              $5
         15        CHECK_UNDEF_ARGS                                         
    5    16        DO_FCALL                                      1  $6      
    9    17      > RETURN                                                   $6
   10    18*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0i5FV
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $arg, !1 = $fulfillment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    6     2        INSTANCEOF                                               !0, 'Placeholder'
          3      > JMPZ                                                     ~2, ->8
    7     4    >   INIT_FCALL                                               'array_shift'
          5        SEND_REF                                                 !1
          6        DO_ICALL                                         $3      
          7      > RETURN                                                   $3
    8     8    > > RETURN                                                   !0
    9     9*     > RETURN                                                   null

End of Dynamic Function 0

End of Dynamic Function 0

End of function curry

Class Placeholder: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.69 ms | 1475 KiB | 21 Q