Author Topic: PHP Closing Tag  (Read 920 times)

Offline toxin

  • Level 21
  • *
  • Posts: 231
  • Reputation: +4/-2
    • View Profile
    • Encore Montreal
PHP Closing Tag
« on: October 29, 2009, 04:32:30 AM »
Just heard about this today. I am sure you all may know but thought to share to anyone that does not.
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. For this reason, all PHP files should OMIT 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.

http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html

Offline Xavier

  • Level 9
  • *
  • Posts: 52
  • Reputation: +1/-1
    • View Profile
Re: PHP Closing Tag
« Reply #1 on: October 29, 2009, 05:05:21 AM »
That is true. CodeIgniter developers encourage this method of marking the end of a PHP file.

Code: [Select]
INCORRECT:
<?php 
echo "Here's my code!"
?>


CORRECT:
<?php 
echo "Here's my code!"
/* End of file myfile.php */ 
/* Location: ./system/modules/mymodule/myfile.php */ 

And I use it too. More about this and other techniques here:

http://codeigniter.com/user_guide/general/styleguide.html#php_closing_tag

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: PHP Closing Tag
« Reply #2 on: October 29, 2009, 09:57:02 AM »
The Drupal CMS also encourages this.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: PHP Closing Tag
« Reply #3 on: October 29, 2009, 10:01:50 AM »
can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages.

Doesn't hurt to write those 2 more characters then :)
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: PHP Closing Tag
« Reply #4 on: October 29, 2009, 10:56:47 AM »
Doesn't hurt to write those 2 more characters then :)
LOL, love this answer. I will stick to the 2 additional chars as well :D

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: PHP Closing Tag
« Reply #5 on: October 29, 2009, 02:53:08 PM »
can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages.

Doesn't hurt to write those 2 more characters then :)

Yeah, I kinda like errors... at least you know what's going on then.

Offline Xavier

  • Level 9
  • *
  • Posts: 52
  • Reputation: +1/-1
    • View Profile
Re: PHP Closing Tag
« Reply #6 on: October 29, 2009, 03:01:35 PM »
I find FirePHP more suitable for PHP debugging than regular errors. Together with Firebug (FF plugin) it makes a great debugging tool for all your JavaScript and PHP code.

http://getfirebug.com/
http://firephp.org/

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal