Thursday, August 2, 2018

syntax - In PHP, why does not show a parse error?



I was running the following PHP code:



    
?>



There were no parse errors and the output was "?>" (example).



In similar cases I do get a parse error:



    

?>




Parse error: syntax error, unexpected '<' in ...




Why doesn't ?> give the same error?


Answer



This must be because there are various ways of starting a block of PHP code:





  • (known as short_open_tag)


  • (the standard really)


  • (not recommended)


  • <% ... %> (deprecated and removed ASP-style tag after 5.3.0)




Apparently, you can open a PHP block one way, and close it the other. Didn't know that.



So in your code, you opened the block using but PHP recognizes as the closer. What happened was:




   <----- END PHP
?> <----- JUST GARBAGE IN THE HTML

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...