In situations when we need to write something like this:
if ($doStuff) {
$obj->doStuff();
}
is it acceptable to write something like this?
$doStuff && $obj->doStuff();
If not, why?
3
For me, it’s not good practice.
First, it hides the logic. Everyone can easily see what the if-construction means. The other is just… “clever” coding, which you shouldn’t do.
You can’t reorder the two things, although generally, you should be able to (oh wait, there are side effects!).
The result of the expression is not used? Hmm… I might just delete that line of code.
Also, I don’t think doing boolean operations with parameters that are maybe void/null/… is a good thing.