3v4l.org

run code in 300+ PHP versions simultaneously
<?php $memoize = function ($fn, $cacheKeyFn = null, $limit = null) { $cache = array(); return function () use ($fn, $cacheKeyFn, $limit, & $cache) { $args = func_get_args(); if ($cacheKeyFn) { $key = call_user_func_array($cacheKeyFn, $args); } else { $key = reset($args); } if (isset($cache[$key])) { return $cache[$key]; } $result = call_user_func_array($fn, $args); if ($limit !== null && count($cache) === $limit) { array_shift($cache); } $cache[$key] = $result; return $result; }; }; $numCalls = 0; $memoFib = $memoize( function ($n) use (& $memoFib, & $numCalls) { $numCalls++; if ($n === 1 || $n === 2) return 1; return $memoFib($n - 1) + $memoFib($n - 2); } ); echo $memoFib(0) . PHP_EOL; echo $memoFib(1) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nafJt
function name:  (null)
number of ops:  21
compiled vars:  !0 = $memoize, !1 = $numCalls, !2 = $memoFib
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FnafJt%3A3%240'
          1        ASSIGN                                                   !0, ~3
   24     2        ASSIGN                                                   !1, 0
   25     3        INIT_DYNAMIC_CALL                                        !0
   26     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FnafJt%3A26%242'
          5        BIND_LEXICAL                                             ~6, !2
          6        BIND_LEXICAL                                             ~6, !1
   30     7        SEND_VAL_EX                                              ~6
          8        DO_FCALL                                      0  $7      
   25     9        ASSIGN                                                   !2, $7
   33    10        INIT_DYNAMIC_CALL                                        !2
         11        SEND_VAL_EX                                              0
         12        DO_FCALL                                      0  $9      
         13        CONCAT                                           ~10     $9, '%0A'
         14        ECHO                                                     ~10
   34    15        INIT_DYNAMIC_CALL                                        !2
         16        SEND_VAL_EX                                              1
         17        DO_FCALL                                      0  $11     
         18        CONCAT                                           ~12     $11, '%0A'
         19        ECHO                                                     ~12
         20      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FnafJt%3A3%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nafJt
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $fn, !1 = $cacheKeyFn, !2 = $limit, !3 = $cache
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
    4     3        ASSIGN                                                   !3, <array>
    5     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FnafJt%3A5%241'
          5        BIND_LEXICAL                                             ~5, !0
          6        BIND_LEXICAL                                             ~5, !1
          7        BIND_LEXICAL                                             ~5, !2
          8        BIND_LEXICAL                                             ~5, !3
   21     9      > RETURN                                                   ~5
   22    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FnafJt%3A3%240

Function %00%7Bclosure%7D%2Fin%2FnafJt%3A5%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 31
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
Branch analysis from position: 21
filename:       /in/nafJt
function name:  {closure}
number of ops:  39
compiled vars:  !0 = $fn, !1 = $cacheKeyFn, !2 = $limit, !3 = $cache, !4 = $args, !5 = $key, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
    6     4        FUNC_GET_ARGS                                    ~7      
          5        ASSIGN                                                   !4, ~7
    7     6      > JMPZ                                                     !1, ->13
    8     7    >   INIT_USER_CALL                                0          'call_user_func_array', !1
          8        SEND_ARRAY                                               !4
          9        CHECK_UNDEF_ARGS                                         
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !5, $9
         12      > JMP                                                      ->17
   10    13    >   INIT_FCALL                                               'reset'
         14        SEND_REF                                                 !4
         15        DO_ICALL                                         $11     
         16        ASSIGN                                                   !5, $11
   12    17    >   ISSET_ISEMPTY_DIM_OBJ                         0          !3, !5
         18      > JMPZ                                                     ~13, ->21
   13    19    >   FETCH_DIM_R                                      ~14     !3, !5
         20      > RETURN                                                   ~14
   15    21    >   INIT_USER_CALL                                0          'call_user_func_array', !0
         22        SEND_ARRAY                                               !4
         23        CHECK_UNDEF_ARGS                                         
         24        DO_FCALL                                      0  $15     
         25        ASSIGN                                                   !6, $15
   16    26        TYPE_CHECK                                  1020  ~17     !2
         27      > JMPZ_EX                                          ~17     ~17, ->31
         28    >   COUNT                                            ~18     !3
         29        IS_IDENTICAL                                     ~19     !2, ~18
         30        BOOL                                             ~17     ~19
         31    > > JMPZ                                                     ~17, ->35
   17    32    >   INIT_FCALL                                               'array_shift'
         33        SEND_REF                                                 !3
         34        DO_ICALL                                                 
   19    35    >   ASSIGN_DIM                                               !3, !5
         36        OP_DATA                                                  !6
   20    37      > RETURN                                                   !6
   21    38*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FnafJt%3A5%241

Function %00%7Bclosure%7D%2Fin%2FnafJt%3A26%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/nafJt
function name:  {closure}
number of ops:  21
compiled vars:  !0 = $n, !1 = $memoFib, !2 = $numCalls
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   27     3        PRE_INC                                                  !2
   28     4        IS_IDENTICAL                                     ~4      !0, 1
          5      > JMPNZ_EX                                         ~4      ~4, ->8
          6    >   IS_IDENTICAL                                     ~5      !0, 2
          7        BOOL                                             ~4      ~5
          8    > > JMPZ                                                     ~4, ->10
          9    > > RETURN                                                   1
   29    10    >   INIT_DYNAMIC_CALL                                        !1
         11        SUB                                              ~6      !0, 1
         12        SEND_VAL_EX                                              ~6
         13        DO_FCALL                                      0  $7      
         14        INIT_DYNAMIC_CALL                                        !1
         15        SUB                                              ~8      !0, 2
         16        SEND_VAL_EX                                              ~8
         17        DO_FCALL                                      0  $9      
         18        ADD                                              ~10     $7, $9
         19      > RETURN                                                   ~10
   30    20*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FnafJt%3A26%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.26 ms | 1404 KiB | 17 Q