From: johnston dot joshua at gmail dot com Operating system: OS X 10.5.2 PHP version: 5.2.5 PHP Bug Type: Strings related Bug description: Escape sequences being expanded in single quoted strings
Description: ------------ This is either a bug with strings or a documentation bug depending on what you decide is "The PHP Way" When using backslashes in single quoted strings, a double backslash is being interpreted as the escape sequence for a single backslash. This is contrary to what the php manual leads you to believe. The php manual for single quoted strings (php.net/types.string) says: To specify a literal single quote, you will need to escape it with a backslash (\), like in many other languages. If a backslash needs to occur before a single quote or at the end of the string, you need to double it. Note that if you try to escape any other character, the backslash will also be printed! So usually there is no need to escape the backslash itself. It is my opinion that since escape sequences do not work inside single quoted strings that backslashes should exhibit the same behavior. e.g '\'' is a single quote '\' is a parse error '\ ' is a backslash followed by a space '\\' is a single backslash '\\ ' is two backslashes followed by a space I understand that this is a difficult issue that a backslash is sometimes an escape sequence and sometimes not. If this cannot be accomplished then the php manual should be updated to reflect this "gotcha". I did notice a few similar reports regarding this issue and I believe that some clarification should be added. Reproduce code: --------------- <?php echo '\ 1', PHP_EOL; echo '\\ 2', PHP_EOL; echo '\\\ 3', PHP_EOL; echo '\\\\ 4', PHP_EOL; echo '\\\\\ 5', PHP_EOL; echo '\\\\\\ 6', PHP_EOL; Expected result: ---------------- \ 1 \\ 2 \\\ 3 \\\\ 4 \\\\\ 5 \\\\\\ 6 Actual result: -------------- \ 1 \ 2 \\ 3 \\ 4 \\\ 5 \\\ 6 -- Edit bug report at http://bugs.php.net/?id=44397&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44397&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44397&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44397&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44397&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44397&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44397&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44397&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44397&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44397&r=support Expected behavior: http://bugs.php.net/fix.php?id=44397&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44397&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44397&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44397&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44397&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44397&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44397&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44397&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44397&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44397&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44397&r=mysqlcfg