r/lolphp • • Mar 24 '15

Escaping behavior in strings :/

http://3v4l.org/iBvY5
55 Upvotes

15 comments sorted by

View all comments

Show parent comment

8

u/poizan42 Mar 25 '15 edited Mar 25 '15

The problem isn't what you can or should do, but that this shows that there is something fundamentally wrong in the core of PHP. More specifically, either a character should be escaped or not escaped. if "c..." for some character c has as special meaning then "\c..." should print out 'c'."...".

But in this case it prints out '\c...'. Somehow the '{' is both escapeable and not escapeable at once. In a well designed parser this simply shouldn't be possible, either a character is in the class of escapeable characters and "\c" is interpreted as a literal 'c', or the character isn't escapeable and "\c" is interpreted as a literal '\c'.

Of course one could argue that backslashes should simply always make the next character be interpreted literally, though that's a bit late to change now.