1.2.544. If Then Return Favorite¶
Show of hands: which syntax would you prefer in a PHP function - A, B or C? Based on a tweet from Povilas Korop : Show of hands: which syntax would you prefer in a PHP function - A, B or C?
<?php
// Format A : double return
if ($condition) {
return A;
} else {
return B;
}
// Format B : early bailout
if ($condition) {
return A;
}
return B;
// Format C : ternary
return $condition ? A : B;
?>
1.2.544.1. Specs¶
Short name |
Structures/IfThenReturnFavorite |
Rulesets |
|
Exakat since |
2.4.5 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |