Documente Academic
Documente Profesional
Documente Cultură
Class Names
Class names MUST be declared in StudlyCaps. Eg: TestClass
Namespaces
Namespaces and classes MUST follow PSR-0
Constants
Class constants MUST be declared in all upper case with underscore
separators. For example:
<?php
namespace Vendor\Model;
class Foo
{
const VERSION = '1.0';
const DATE_APPROVED = '2012-06-01';
}
Methods
Variable Names
Variable names should be all lowercase, with words separated by underscores.
Names should be descriptive, but also concise. Wherever possible, keep variable
names to a minimum length
Keywords
Keywords such as true, false, null, as, etc should be all lower case, as upper case
is reserved for constants. Same goes for primitive types like array, integer, string.
$var = true;
$var = false;
$var = null;
foreach ($array as $key => $value)
public function my_function(array $array)
function my_function($arg = null)
Including braces
Braces should always be included when writing code using if, for, while etc.
blocks. There are no exceptions to this rule, even if the braces could be
omitted. Leaving out braces makes code harder to maintain in the future and
can also cause bugs that are very difficult to track down.
Incorrect
if ( condition ) foo();
Correct
if ( condition )
{
foo();
}
Function Calls - Functions should be called with no spaces between the function
name, the opening parenthesis, and the first parameter; spaces between commas
and each parameter, and no space between the last parameter, the closing
parenthesis, and the semicolon.
Example;
$this->setFoo($arg1, $arg2 = 0);
Quoting strings
If your string contains no variables, use single quotes and save the parser the
trouble of attempting to interpolate the string for variables.
Shortcut operators
Code Comments
Use comment blocks for classes and methods. Single line comments has to be used
where necessary.
A sample comment block for a class:
/**
* Test class - Controls the test actions
* @author Bridge
* @copyright Bridge India
*/
Editor settings
Indenting and Line Length - Use an indent of 4 spaces and don't use any tab
because different editors use different setting for tab. It is recommended to keep
lines at approximately 75-85 characters long for better code readability.
PHP code MUST use only UTF-8