3 ms·
Depending on the language and values, the latter does not mean the same thing. <?php $x = 1;$y = 2; function test1($x, $y) { if ($x) {
by TooBrokeToBeg 8y ago
Depending on the language and values, the latter does not mean the same thing.
<?php
$x = 1;$y = 2;
function test1($x, $y) {
if ($x) {
return $y;
} else {
return false;
}
}
function test2($x, $y) {
return $x && $y;
}
var_dump(test1($x,$y));
echo "\n";
var_dump(test2($x,$y));
- moomin 8y agoSince we’re discussing readability, let’s be generous and assume the code behaves the same. Since otherwise, it’s not a question of readability anymore. (But yes, incorrect transformations are incorrect.)