3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str="æøå\x01"; var_dump(["str"=>$str,"escapeshellarg"=>escapeshellarg($str), "quoteshellarg"=>quoteshellarg($str)]); /** * quotes shell arguments * (doing a better job than escapeshellarg) * * @param string $arg * @throws UnexpectedValueException if $arg contains null bytes * @return string */ function quoteshellarg(string $arg): string { if (PHP_OS_FAMILY === 'Linux') { // PHP's built-in escapeshellarg() for linux is garbage, corrupting-or-stripping UTF-8 unicode characters like "æøå" // and stripping non-printable characters like \x01 // while single-quoted shell arguments in Linux are binary safe execpt for 2 bytes: \x00 and \x27 // to prevent corruption of UTF-8 characters, we implement our own shell argument quoting for Linux. if (false !== strpos($arg, "\x00")) { throw new UnexpectedValueException('linux shell arguments cannot contain null bytes!'); } return "'" . strtr($arg, array("'" => "'\\''")) . "'"; } // fallback to the php built-in function return escapeshellarg($arg); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hkv7h
function name:  (null)
number of ops:  14
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%C3%A6%C3%B8%C3%A5%01'
    3     1        INIT_FCALL                                               'var_dump'
          2        INIT_ARRAY                                       ~2      !0, 'str'
          3        INIT_FCALL                                               'escapeshellarg'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6        ADD_ARRAY_ELEMENT                                ~2      $3, 'escapeshellarg'
          7        INIT_FCALL_BY_NAME                                       'quoteshellarg'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $4      
         10        ADD_ARRAY_ELEMENT                                ~2      $4, 'quoteshellarg'
         11        SEND_VAL                                                 ~2
         12        DO_ICALL                                                 
   27    13      > RETURN                                                   1

Function quoteshellarg:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 20
Branch analysis from position: 2
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hkv7h
function name:  quoteshellarg
number of ops:  27
compiled vars:  !0 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1      > JMPZ                                                     <true>, ->20
   20     2    >   INIT_FCALL                                               'strpos'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '%00'
          5        DO_ICALL                                         $1      
          6        TYPE_CHECK                                  1018          $1
          7      > JMPZ                                                     ~2, ->12
   21     8    >   NEW                                              $3      'UnexpectedValueException'
          9        SEND_VAL_EX                                              'linux+shell+arguments+cannot+contain+null+bytes%21'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $3
   23    12    >   INIT_FCALL                                               'strtr'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 <array>
         15        DO_ICALL                                         $5      
         16        CONCAT                                           ~6      '%27', $5
         17        CONCAT                                           ~7      ~6, '%27'
         18        VERIFY_RETURN_TYPE                                       ~7
         19      > RETURN                                                   ~7
   26    20    >   INIT_FCALL                                               'escapeshellarg'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $8      
         23        VERIFY_RETURN_TYPE                                       $8
         24      > RETURN                                                   $8
   27    25*       VERIFY_RETURN_TYPE                                       
         26*     > RETURN                                                   null

End of function quoteshellarg

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.38 ms | 960 KiB | 17 Q