PHP CLOSING TAG TIPS


The PHP closing tag?> ) on a PHP document is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. I think you have faced this frustrating issues and had to waste your valuable time to debug. For this reason, all PHP files shouldOMIT the closing PHP tag, and instead use a comment block to mark the end of file and it’s location relative to the application root. This allows you to still identify a file as being complete and not truncated. Here is an example:
BAD PRACTICE:
1<?php 
2echo "Here's my code!"
3?>
GOOD PRACTICE:
1<?php 
2echo "Here's my code!";
Also, while using php code into html pages it is not recommended that you use php short form (<? ?>) because this may not support if it is configured in the php.ini. So, if you use this and found your application is not working and in the same time you can’t modify the php.ini then you have to change those which will kill lots of your time! So best is always use:

No comments:

Post a Comment