3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Example 1 -- Unpacking the array to do work on it array_map(function ($x) { $first_name = $x[0]; $last_name = $x[1]; // Do important work here with first_name and last_name... // But $first_name and $last_name are scoped to this function // See the second example for how we'd inject an anonymous function to operate with $first_name and $last_name }, [ ['John', 'Galt'], ['Howard', 'Roark'], ]); // Example 2 -- Separation of input setup and behavior $behavior = function ($first_name, $last_name) { var_dump('Doing hard work!', $first_name, $last_name); }; array_map(function ($x) use ($behavior) { $first_name = $x[0]; $last_name = $x[1]; // $behavior is invoked using our unpacked arguments $behavior($first_name, $last_name); }, [ ['John', 'Galt'], ['Howard', 'Roark'], ]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F5Y6t
function name:  (null)
number of ops:  14
compiled vars:  !0 = $behavior
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                                   'array_map'
          1        DECLARE_LAMBDA_FUNCTION                              ~1      [0]
   12     2        SEND_VAL                                                     ~1
   13     3        SEND_VAL                                                     <array>
    4     4        DO_ICALL                                                     
   19     5        DECLARE_LAMBDA_FUNCTION                              ~3      [1]
          6        ASSIGN                                                       !0, ~3
   23     7        INIT_FCALL                                                   'array_map'
          8        DECLARE_LAMBDA_FUNCTION                              ~5      [2]
          9        BIND_LEXICAL                                                 ~5, !0
   29    10        SEND_VAL                                                     ~5
   30    11        SEND_VAL                                                     <array>
   23    12        DO_ICALL                                                     
   32    13      > 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/F5Y6t
function name:  {closure:/in/F5Y6t:4}
number of ops:  6
compiled vars:  !0 = $x, !1 = $first_name, !2 = $last_name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
    5     1        FETCH_DIM_R                                          ~3      !0, 0
          2        ASSIGN                                                       !1, ~3
    6     3        FETCH_DIM_R                                          ~5      !0, 1
          4        ASSIGN                                                       !2, ~5
   12     5      > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F5Y6t
function name:  {closure:/in/F5Y6t:19}
number of ops:  8
compiled vars:  !0 = $first_name, !1 = $last_name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   20     2        INIT_FCALL                                                   'var_dump'
          3        SEND_VAL                                                     'Doing+hard+work%21'
          4        SEND_VAR                                                     !0
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                                     
   21     7      > RETURN                                                       null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F5Y6t
function name:  {closure:/in/F5Y6t:23}
number of ops:  11
compiled vars:  !0 = $x, !1 = $behavior, !2 = $first_name, !3 = $last_name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   24     2        FETCH_DIM_R                                          ~4      !0, 0
          3        ASSIGN                                                       !2, ~4
   25     4        FETCH_DIM_R                                          ~6      !0, 1
          5        ASSIGN                                                       !3, ~6
   28     6        INIT_DYNAMIC_CALL                                            !1
          7        SEND_VAR_EX                                                  !2
          8        SEND_VAR_EX                                                  !3
          9        DO_FCALL                                          0          
   29    10      > RETURN                                                       null

End of Dynamic Function 2

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.99 ms | 2787 KiB | 15 Q