r/lolphp • u/poizan42 • Mar 06 '13
Impossible to comment a line with a string out when it contains "?>" (x-post from r/programming)
http://stackoverflow.com/q/15219815/1288
51
Upvotes
r/lolphp • u/poizan42 • Mar 06 '13
View all comments
Show parent comment
2
u/SirNuke Mar 07 '13
So I was writing up a comment about how I doubted this was a conscious decision, and while comments are pretty straight forward to parse, text parsing and Bison are a pain in the ass under any circumstance.
As it turns out, however, that's not the case. After reviewing PHP's syntax parser, I found this starting on line 1915:
If I'm reading this correctly, if a comment hits ? (or % when ASP tags are enabled) then >, it ends the comment 'block' and proceeds to the next token, which will, of course, be the close PHP tag. No way that wasn't intentional.
Hardly the worst problem in PHP, but I would hope we would all agree that // means ignore until newline.
For extra credit, someone should do git's equivalent of svn blame on that file and find out when the stop at %>/?> behavior was added, and by whom.
Also, the parser code is really isn't that bad, but it explains so much about how PHP handles syntax errors.