3v4l.org

run code in 300+ PHP versions simultaneously
<?php function interpolate($str, array $context = [], $asIs = false) { $replace = []; foreach ($context as $key => $val) { if ($asIs) { $replace[$key] = $val; } else { $replace['{{' . $key . '}}'] = $val; } } return strtr($str, $replace); } echo interpolate('user-id-513', [ '-' => '/', '--' => '-', ], true); echo PHP_EOL; echo interpolate('wizard-add--a--photo', [ '-' => '/', '--' => '-', ], true);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hnuEY
function name:  (null)
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'interpolate'
          1        SEND_VAL                                                 'user-id-513'
   16     2        SEND_VAL                                                 <array>
   18     3        SEND_VAL                                                 <true>
          4        DO_FCALL                                      0  $0      
          5        ECHO                                                     $0
   19     6        ECHO                                                     '%0A'
   20     7        INIT_FCALL                                               'interpolate'
          8        SEND_VAL                                                 'wizard-add--a--photo'
   21     9        SEND_VAL                                                 <array>
   23    10        SEND_VAL                                                 <true>
         11        DO_FCALL                                      0  $1      
         12        ECHO                                                     $1
         13      > RETURN                                                   1

Function interpolate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/hnuEY
function name:  interpolate
number of ops:  23
compiled vars:  !0 = $str, !1 = $context, !2 = $asIs, !3 = $replace, !4 = $val, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
          2        RECV_INIT                                        !2      <false>
    4     3        ASSIGN                                                   !3, <array>
    5     4      > FE_RESET_R                                       $7      !1, ->16
          5    > > FE_FETCH_R                                       ~8      $7, !4, ->16
          6    >   ASSIGN                                                   !5, ~8
    6     7      > JMPZ                                                     !2, ->11
    7     8    >   ASSIGN_DIM                                               !3, !5
          9        OP_DATA                                                  !4
         10      > JMP                                                      ->15
    9    11    >   CONCAT                                           ~11     '%7B%7B', !5
         12        CONCAT                                           ~12     ~11, '%7D%7D'
         13        ASSIGN_DIM                                               !3, ~12
         14        OP_DATA                                                  !4
    5    15    > > JMP                                                      ->5
         16    >   FE_FREE                                                  $7
   12    17        INIT_FCALL                                               'strtr'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $14     
         21      > RETURN                                                   $14
   13    22*     > RETURN                                                   null

End of function interpolate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.47 ms | 1403 KiB | 17 Q