PHP: The Second Bracket Is Optional

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

<?php 
class Users
{
}
?>

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

<?php 
class Users
{
}

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.
CAPTCHA
16 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.