Why if( constant == variable ) is preferred instead of if ( variable == constant )
Here is an answer to your question.
This helps in debugging if you miss an equal sign.
Because that form makes it harder to introduce a bug by forgetting one
of the equals signs. Imagine if you did this:
if (k = 5) This was intended as a comparison, but it's now an
assignment! What's worse, it is legal, and it will mess up your
program in multiple ways (the value of k is changed, and the
conditional always evaluates to true).
Contrast this with
if (5 = k) This is not legal (you cannot assign to a literal) so the
compiler will immediately flag it as an error.
in the words of Hanky 웃 Panky in comments:
They are both equivalent but 'string'==$var is a better approach
because it helps in debugging if you miss an equal sign.