I've seen a lot this kind of code recently:
if ($foo = $bar->getFoo())
{
baz($foo);
}
Is this considered good or bad practice?
For example, the NetBeans IDE give a notice if you use this kind of code:
Possible accidental assignment, assignments in conditions should be avoided
What do you think?
It's a useful tool that I have to admit to using on occasion to avoid an extra line for an assignment. On the one hand, it may be bad practice by some because:
On the other hand:
I should note that I do try to avoid it because I find it less readable most of the time, but it's purely personal preference for me. Where I find it useful, I use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With