Chapters
PHP Coding Standards
Naming Convention
Files should be named descriptively using lowercase letters. Hyphens should separate words: my-file-name.php
Indentation
Your indentation should always reflect logical structure. Use real tabs, not spaces, as this allows the most flexibility across clients.
Exception: if you have a block of code that would be more readable if things are aligned, use spaces:
Syntax
Please use the alternative syntax when writing control structures that mix PHP and HTML. This will help tremendously with readability. It may look fine to use the curly braces for your control structures, but it starts to get very easy to lose where a curly brace starts and where it ends on larger, more complex code blocks.
Correct
Incorrect
Print Statements
Whether you want to use <?php echo $variable; ?> or <?php print $variable; ?> or <?= $variable; ?> is up to you. However, I personally like to use the latter: <?= $variable; ?> just because it’s ever so slightly faster and easier to write and also looks more clean. Therefore you will see that variation a lot throughout our boilerplate codebase.