Home >Backend Development >PHP Tutorial >PHP coding standards (23)_PHP tutorial
9.1 Constants
Numeric constants located in for loops as counter values, except -1, 0 and 1, should not be written directly into the code.
9.2 Variable assignment
Avoid assigning the same value to multiple variables in one statement. It's hard to read. For example:
$fooBar.fChar = $barFoo.lchar = c; // Error
Do not use the assignment operator in a place where it is easily confused with the equality operator. For example:
if ($c++ = $d++) { // Error
...
}
should be written as
if (($c++ = $d++) != 0 ) {
...
}
Do not use embedded assignment operators to try to improve runtime efficiency. This is the job of the compiler. For example:
$d = ($a = $b + $c) + $r; // The error
should be written as
$a = $b + $c;
$d = $a + $r;