3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringHelper { public 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); } } class CacheKeysDict { protected static $stringHelper = null; const BOT_ACTIVITY_MESSAGES = 'bot_activity_messages'; const PROFILE = 'profile_{{id}}'; public static function prepareKey($key, array $context = []) { return self::getStringHelper()->interpolate($key, $context); } public static function getStringHelper() { if (is_null(self::$stringHelper)) { self::$stringHelper = new StringHelper; } return self::$stringHelper; } } var_dump([ CacheKeysDict::BOT_ACTIVITY_MESSAGES, CacheKeysDict::prepareKey(CacheKeysDict::BOT_ACTIVITY_MESSAGES), CacheKeysDict::prepareKey(CacheKeysDict::PROFILE, ['id' => 503]), ]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A3A4F
function name:  (null)
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   INIT_FCALL                                               'var_dump'
   41     1        INIT_ARRAY                                       ~0      'bot_activity_messages'
   42     2        INIT_STATIC_METHOD_CALL                                  'CacheKeysDict', 'prepareKey'
          3        SEND_VAL                                                 'bot_activity_messages'
          4        DO_FCALL                                      0  $1      
          5        ADD_ARRAY_ELEMENT                                ~0      $1
   43     6        INIT_STATIC_METHOD_CALL                                  'CacheKeysDict', 'prepareKey'
          7        SEND_VAL                                                 'profile_%7B%7Bid%7D%7D'
          8        SEND_VAL                                                 <array>
          9        DO_FCALL                                      0  $2      
         10        ADD_ARRAY_ELEMENT                                ~0      $2
         11        SEND_VAL                                                 ~0
         12        DO_ICALL                                                 
   44    13      > RETURN                                                   1

Class StringHelper:
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/A3A4F
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
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
          2        RECV_INIT                                        !2      <false>
    7     3        ASSIGN                                                   !3, <array>
    8     4      > FE_RESET_R                                       $7      !1, ->16
          5    > > FE_FETCH_R                                       ~8      $7, !4, ->16
          6    >   ASSIGN                                                   !5, ~8
    9     7      > JMPZ                                                     !2, ->11
   10     8    >   ASSIGN_DIM                                               !3, !5
          9        OP_DATA                                                  !4
         10      > JMP                                                      ->15
   12    11    >   CONCAT                                           ~11     '%7B%7B', !5
         12        CONCAT                                           ~12     ~11, '%7D%7D'
         13        ASSIGN_DIM                                               !3, ~12
         14        OP_DATA                                                  !4
    8    15    > > JMP                                                      ->5
         16    >   FE_FREE                                                  $7
   15    17        INIT_FCALL                                               'strtr'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $14     
         21      > RETURN                                                   $14
   16    22*     > RETURN                                                   null

End of function interpolate

End of class StringHelper.

Class CacheKeysDict:
Function preparekey:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A3A4F
function name:  prepareKey
number of ops:  10
compiled vars:  !0 = $key, !1 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   28     2        INIT_STATIC_METHOD_CALL                                  'getStringHelper'
          3        DO_FCALL                                      0  $2      
          4        INIT_METHOD_CALL                                         $2, 'interpolate'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $3      
          8      > RETURN                                                   $3
   29     9*     > RETURN                                                   null

End of function preparekey

Function getstringhelper:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/A3A4F
function name:  getStringHelper
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'stringHelper'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->7
   34     3    >   NEW                                              $3      'StringHelper'
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'stringHelper'
          6        OP_DATA                                                  $3
   36     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'stringHelper'
          8      > RETURN                                                   ~5
   37     9*     > RETURN                                                   null

End of function getstringhelper

End of class CacheKeysDict.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.78 ms | 1400 KiB | 17 Q