PHP: The Second Bracket Is Optional

14th October 2009 - 1 minute read time

When writing PHP class or function (basically any file containing only PHP code) files you might have learnt to write them something like this:

  1. <?php
  2. class Users
  3. {
  4. }
  5. ?>

However, did you know that the second bracket is optional? The following class file is perfectly legal:

  1. <?php
  2. class Users
  3. {
  4. }

This practice is actually a good thing to do for a very good reason, it will stop any white space appearing at the bottom of your files, which can cause header errors. In fact, missing out the second brace is part of the Zend Framework coding standard for this very reason, so it is a good habit to get into.

Add new comment

The content of this field is kept private and will not be shown publicly.