3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_map_via_callback($f, $a) { $o = []; $c = function ($v) use (&$o) { $o[] = $v; }; foreach ($a as $k => $v) $f($v, $c); return $o; } // Mapping $x => $x ^ 2 function forClassicMap($x) { return $x * $x; } $mapped1 = array_map('forClassicMap', [1, 2, 3]); // Mapping $x => $x ^ 2 via callback function forMapViaCallback($x, $callback) { $callback($x * $x); } $mapped2 = array_map_via_callback('forMapViaCallback', [1, 2, 3]); var_dump($mapped1, $mapped2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TBTFj
function name:  (null)
number of ops:  15
compiled vars:  !0 = $mapped1, !1 = $mapped2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'array_map'
          1        SEND_VAL                                                 'forClassicMap'
          2        SEND_VAL                                                 <array>
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   24     5        INIT_FCALL                                               'array_map_via_callback'
          6        SEND_VAL                                                 'forMapViaCallback'
          7        SEND_VAL                                                 <array>
          8        DO_FCALL                                      0  $4      
          9        ASSIGN                                                   !1, $4
   27    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function array_map_via_callback:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/TBTFj
function name:  array_map_via_callback
number of ops:  17
compiled vars:  !0 = $f, !1 = $a, !2 = $o, !3 = $c, !4 = $v, !5 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, <array>
    4     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTBTFj%3A4%240'
          4        BIND_LEXICAL                                             ~7, !2
          5        ASSIGN                                                   !3, ~7
    7     6      > FE_RESET_R                                       $9      !1, ->14
          7    > > FE_FETCH_R                                       ~10     $9, !4, ->14
          8    >   ASSIGN                                                   !5, ~10
          9        INIT_DYNAMIC_CALL                                        !0
         10        SEND_VAR_EX                                              !4
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0          
         13      > JMP                                                      ->7
         14    >   FE_FREE                                                  $9
    8    15      > RETURN                                                   !2
    9    16*     > RETURN                                                   null

End of function array_map_via_callback

Function %00%7Bclosure%7D%2Fin%2FTBTFj%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TBTFj
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $v, !1 = $o
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    5     2        ASSIGN_DIM                                               !1
          3        OP_DATA                                                  !0
    6     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTBTFj%3A4%240

Function forclassicmap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TBTFj
function name:  forClassicMap
number of ops:  4
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        MUL                                              ~1      !0, !0
          2      > RETURN                                                   ~1
   17     3*     > RETURN                                                   null

End of function forclassicmap

Function formapviacallback:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TBTFj
function name:  forMapViaCallback
number of ops:  7
compiled vars:  !0 = $x, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        INIT_DYNAMIC_CALL                                        !1
          3        MUL                                              ~2      !0, !0
          4        SEND_VAL_EX                                              ~2
          5        DO_FCALL                                      0          
   23     6      > RETURN                                                   null

End of function formapviacallback

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.48 ms | 1403 KiB | 18 Q