Is (true === $var) the same as ($var === true)?


I've read that it's generally better to use if(true === $var) rather than just if($var) for various reasons.

But I've seen it as (true === $var) when It would appear more logical to me to do ($var === true).

Is there a difference?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shahzad Fateh AliWeb Solutions Architect & Technical Project Manager- VentureDive (Pvt) LtdCommented:
No, there are not difference in both statements, but it depends of the understanding for the programmer that how he/she wants to write it.
No, those statements are interchangable.
There is no difference, "===" instead of "==" just compares the type as well as the value of the variables.

For more information, see

Hope this helps.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Actually it is programmers' technique to eliminate coding mistakes.

In example:

Lets say you are checking if $var is equal to true.
Then you write:
if ($var == true)

Right, but if you forget one "=", your condition becomes:
if ($var = true)
which returns always true because you are setting the $var value to true  and you will not be able to correct it.
However if you want to write

if (true == $var)
and you forget one "=", then your condition becomes:
if (true = $var)
and you will be shown an error and you will be able to correct it.

Thats the idea.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Avinash ZalaWeb ExpertCommented:
== will compare only values


=== will compare value as well as data type.

Hope this helps.
i-CONICAAuthor Commented:
Thanks guys.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.