PHP: The format of the conditions is (6 == $ var) or ($ var == 6)?

I looked through these PHP Coding Rules (a bit dated but very interesting) and found this:

Format of conditions

Always put a constant on the left side of the equality / inequality comparison. For example: if ( 6 == $errorNum )...

One reason is that if you do not specify one of the = icons, the parser will find an error for you. The second reason is that it puts the value you are looking for right where you can find it instead of being buried at the end of your expression. It takes a little time to get used to this format, but then it really becomes useful.

I have ($var == 6)been using it for many years, and the idea of ​​putting them the other way is terrible. But, as already mentioned, it takes a little time to get used to and should have clear advantages. We just write the standard in our company, so if we want to change this, now is the time to do it. But I would like to hear if others have experience with this particular format. Any opinions?

EDIT

I'm interested in the experience of communicating with this switch. For me, and most likely for others, it looks like a big change that you need to get used to. But it looks interesting. So, the question is for those who have switched: can you recommend this change?

+5
source share
1 answer

6 == $var , $var == 6 . , -. . , , . , .

, , , , , :

if ($var = 6) {} //weird semantic error
if (6 = $var) {} //parse error
+6

All Articles