php - What difference does variable order/side make with relational operators? -
compare:
if (donald_duck != null) if (roast_potatoes > 9000) if (love === 'explosions') and
if (null != donald_duck) if (9000 <= roast_potatoes) if ('explosions' === love) in languages i've written in, i've used first order since makes sense human-wise. e.g. "is parrot dead?" vs "is dead parrot is?" i've seen (null == variable) order used few times in various languages , places.
what operational difference make, , 1 way more syntactically correct or adopted?
(i'm aware may different various languages, in particular i'm asking in regards php)
there no different in behavior helps avoid errors example in comparisons.
if use obj == null compare, have risk of making mistake , putobj = null instead causing problems in code , having unexpected results.
but if use null == obj compare, risk goes away because null = obj not valid sentence (you can't assign object null) , receive error in compile time.
hope helps
Comments
Post a Comment