There are many "Why does PHP throw an error here?" questions. Well, that is a little different. I found the following code while processing code written by a colleague:
foreach($arr as $key => $value) {http:
My first thought: βUmm ... how embarrassing, he must have accidentally pasted it there ...β and then: βWait ... there is no way this code really works ... it should be a syntax error " But still:
$ php -l test.php No syntax errors detected
And indeed (like many PHP codes that don't seem to be running), it works without problems. So I did a little testing:
foreach($arr as $key => $value) {http://google.com/ <-- original, no error foreach($arr as $key => $value) {http: <-- also no syntax error foreach($arr as $key => $value) {http <-- bingo! "Unexpected T_ECHO..."
What little tidbit of PHP grammar produces such weird results?
(I am using PHP 5.3.5)
source share