I’m been searching what the correct PHP convention is for assignments in conditions.
<?php
if(false !== ($var = something())) {
...
}
// or
if(($var = something()) !== false) {
...
}
Usually I’m using the first solution for small methods that I don’t want to clutter with too much code, but some of my collegues use it the other way. What would be the right one to use and why?
I know that functionally it doesn’t matter at all, I’m just asking this for enlightenment on conventions.
Thanks in advance.
Do it the way the code base does it. Don’t be that guy who injects your own preferences into the collective which clash with the norm.