Home >Backend Development >PHP Tutorial >PHP coding standards (19)_PHP tutorial
7.2 Space
Spaces should be used in the following situations:
- A keyword immediately followed by brackets should be separated by spaces, for example:
while ( true ) {
...
}
Note: Spaces should not be placed between the method name and its opening bracket. This will help distinguish keywords from method calls.
- Whitespace should follow the comma in the argument list
- All binary operators, except ".", should be separated from their operands by whitespace. There should be no spaces between unary operators and operands, such as negative sign ("-"), increment ("++") and decrement ("--"). For example:
$a += $c + $d;
$a = ( $a + $b ) / ( $c * $d );
while ( $d++ = $s++ ) {
$n++;
}
printSize( "size is " + $foo + "
" );
- The expression in the for statement should be separated by spaces, for example:
for (expr1; expr2; expr3)
- The cast should be followed by a space, for example :
myMethod( (byte) $aNum, (int) $x );
myMethod( (int) ($cp + 5 ), ( (int) ($i + 3)) + 1 );