3v4l.org

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

End of function quoteshellarg

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.92 ms | 1883 KiB | 19 Q