0

Why we are using triple equals here to compare ?

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
}
StealthTrails
  • 2,281
  • 8
  • 43
  • 67
  • 3
    [RTM](http://php.net/manual/en/mysqli.query.php) – Rizier123 Jul 05 '15 at 13:50
  • @mario My question is clearly different , I am asking in another sense that why we are using triple equals for comparing with boolean but the other question only asks the difference between =,== and ===. Please try to read the question before marking it duplicate. – StealthTrails Jul 05 '15 at 15:19
  • I fail to see the uniqueness of your question. The [difference between `==` and `===`](https://www.google.de/search?q=site%3Astackoverflow.com+php+difference+between+%3D%3D+and+%3D%3D%3D+equals) comes up every other week. And it's *also* answered by the linked answers. If you want to differentiate yours from prior questions, just write a less coarse question. – mario Jul 05 '15 at 15:35
  • @mario I did not know that `$conn->query($sql)` can return true , false and object . If I did not ask it I how would I know it ? At least now I know about it , the other questions with whom you are matching my question , they are asking about the differences of =,== and === and I know it . Now you even can delete the question , go ahead. – StealthTrails Jul 05 '15 at 19:54

1 Answers1

2

Many PHP functions may return mixed types, unlike many other languages. If you would compare with ==, only values would be tested. Therefore any non-zero value would be equal to true, and also things like 123 == '123abc' would be true.

The === operator requires types to be the same also, so any object is not equal to true and even 123 === '123' doesn't equal true.

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74