
Variable names
- The first letter of a variable must start with lowercase
- Variables native or arrays must be separated by underscore(_) every word change: $my_var
- The variables that are Objects each word end must be capitalized, example: $myVar
- Global variables must be all capitalized, example: $MY_VAR
Assignments
- There must be a space between the variable and the operators:
$my_var = 17; $a = $b;
Operators
- “+”, “-“, “*”, “/”, “=” y cualquier combinación de ellos (ej. “/=”) necesitan un espacio entre
members of the left and right$a +17;$result = $b /2;$i + =34; - “.” no llevan espacio entre los miembros de la izquierda y la derecha
echo $a.$b;$c = $d.$Este-> foo ();Recommendation
For performance reasons, do not exceed the use of concatenation.
- “.=” necesita un espacio entre los miembros de la izquierda y la derecha
$a. ='Debug';
Declarations
- if, elseif, while, for: must have a space between the if keyword and the parentheses
if( )while( ) - When a combination of if and else else is used and if both must offer a value, the else must be avoided.
if( )returnfalse;returntrue;Recommendation
We recommend one result per method / function
- When a method / function offers a boolean value and the current value of the method / function depends on it, the if statement should be avoided
publicaFirstMethod (){return$Este-> aSecondMethod ();} - Las pruebas deben ser agrupadas por “entidad”
if($price AND! Empty ($price))[...]if(! Validate :: $myObject OR $myObject-> id === NULL)[...]
Visibility
- Visibility must be defined at all times, even when it is a public method.
- The order of the method properties must be: visibility static function name ()
privatestaticfunction foo ()
Method / Function Names
- Method and function names always start with a lowercase character and each of the following words must start with an uppercase character (CamelCase)
publicfunction myExempleMethodWithALotOfWordsInItsName () - The brackets that are presented in the method code have to be preceded by a return
publicfunction myMethod ($arg1, $arg2){[...]} - Los nombres de los métodos y las funciones deben ser nombres explícitos, por lo tanto nombres de función como “b()” o “ef()” están completamente prohibidos.Excepciones
Las únicas excepciones son la función de traducción llamada “l()” y las funciones de depuración “p()”, “d()”.
Enumeration
Commas must be followed (and only followed) by a space.
protected function myProtectedMethod ($arg1, $arg2, $arg3 = null) |
Objects / Classes
- The name of the object must be singular
classCustomer - The class name must follow the CamelCase model, except that the first letter is capitalized
classMyBeautifulClass
Definitions
- Definitions names must be entered in uppercase
- Los nombres de las definiciones deben contar con el prefijo “PS_” dentro del núcleo y el módulo
define ('PS_DEBUG',1);define ('PS_MODULE_NAME_DEBUG',1); - Definition names do not allow alphabetic characters. Except "_".
Keywords
All keywords must be lowercase
ex. as, case, if, echo, null
Constants
Las constantes deben estar en mayúsculas, excepto “verdadero” y “falso” y “nulo”, que debe estar en minúsculas
ej. “ENT_NOQUOTE”, “true”
Configuration variables
Configuration variables follow the same rules as definitions
Chains
Strings must be enclosed in single quotes, never double
threw out 'Debug';
|
Comments
- Dentro de las funciones y métodos, sólo la etiqueta “//” de comentario es permitida
- Después de la etiqueta “//” de comentario, un espacio “// Comment“ es necesario
// My great comment - La etiqueta “//” de comentario es permitida al final de una línea de código
$a =17+23;// A comment inside my exemple function - Funciones y métodos externos, sólo las etiquetas “/” y “/” de comentario son permitidas
/ * This method is required for compatibility issues * /publicfunction foo (){// Some code explanation right here[...]} - Comment PHP Doc Element is required before method declarations
/*** Return field value if possible (both classical and multilingual fields)** Case 1: Return value if present in $_POST / $_GET* Case 2: Return object value** @param object $obj Object* @param string $key Field name* @param integer $id_lang Language id (optional)* @return string*/protectedfunction getFieldValue ($obj, $key, $id_lang = NULL)For more information
For more information about the PHP Doc rule: see this useful link
Return of values
- Return declarations do not need parentheses, except for a compound expression
return$result;return($a + $b);return(a () - b ());returntrue; - Disarm a function
return;
Call
La función de llamada precedida por una “@” está prohibida pero tenga cuidado con la llamada a la función / método con login / contraseña o ruta de argumentos.
myfunction ()
|
Labels
- A blank line should be left after the PHP opening tag
<?phprequire_once ('my_file.inc.php'); - Final PHP tag is forbidden
Indentation
- El carácter de tabulación (“\t”) es el único caracter de indentación que se permite
- Each level of indentation must be represented by a single tab character
function foo ($a){if($a ==null)returnfalse;[...]}
Matrix
- The array keyword must not be followed by a space
array (17,23,42); - The indentation should be as follows when a lot of data is inside an array:
$a = array (36=> $b,$c =>'foo',$d => array (17,23,42),$e => array (0=>'zero',1=> $one));
Block
Square brackets are prohibited when defining only one statement or statement combination
if (! $result)
|
No Comment