3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!defined('JSON_UNESCAPED_UNICODE')) { define('JSON_UNESCAPED_SLASHES', 64); define('JSON_UNESCAPED_UNICODE', 256); } $original = 'foo/bar'; $q = array('query_string' => escapeTerm($original)); $j = json_encode($q); var_dump($j); function escapeTerm($term) { $result = $term; // \ escaping has to be first, otherwise escaped later once again $chars = array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/'); foreach ($chars as $char) { $result = str_replace($char, '\\' . $char, $result); } return $result; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 1, Position 2 = 9
Branch analysis from position: 1
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/5gE31
function name:  (null)
number of ops:  23
compiled vars:  !0 = $original, !1 = $q, !2 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E > > JMPZ                                                     <false>, ->9
    4     1    >   INIT_FCALL                                               'define'
          2        SEND_VAL                                                 'JSON_UNESCAPED_SLASHES'
          3        SEND_VAL                                                 64
          4        DO_ICALL                                                 
    5     5        INIT_FCALL                                               'define'
          6        SEND_VAL                                                 'JSON_UNESCAPED_UNICODE'
          7        SEND_VAL                                                 256
          8        DO_ICALL                                                 
    8     9    >   ASSIGN                                                   !0, 'foo%2Fbar'
    9    10        INIT_FCALL_BY_NAME                                       'escapeTerm'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $6      
         13        INIT_ARRAY                                       ~7      $6, 'query_string'
         14        ASSIGN                                                   !1, ~7
   10    15        INIT_FCALL                                               'json_encode'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $9      
         18        ASSIGN                                                   !2, $9
   11    19        INIT_FCALL                                               'var_dump'
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                                 
   24    22      > RETURN                                                   1

Function escapeterm:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/5gE31
function name:  escapeTerm
number of ops:  16
compiled vars:  !0 = $term, !1 = $result, !2 = $chars, !3 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, !0
   17     2        ASSIGN                                                   !2, <array>
   19     3      > FE_RESET_R                                       $6      !2, ->13
          4    > > FE_FETCH_R                                               $6, !3, ->13
   20     5    >   INIT_FCALL                                               'str_replace'
          6        SEND_VAR                                                 !3
          7        CONCAT                                           ~7      '%5C', !3
          8        SEND_VAL                                                 ~7
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !1, $8
   19    12      > JMP                                                      ->4
         13    >   FE_FREE                                                  $6
   23    14      > RETURN                                                   !1
   24    15*     > RETURN                                                   null

End of function escapeterm

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.63 ms | 1392 KiB | 21 Q