PHP == or ===, why is my string equal to zero
Our lecturer says "always use ===" but never says why, so I tested it. On my laptop (PHP 8.3):
Cite
CoursesWeb Forum, "PHP == or ===, why is my string equal to zero", https://coursesweb.net/forum/t/php-or-why-is-my-string-equal-to-zero/, accessed 2026-12-06.var_dump("abc" == 0); // bool(false) var_dump("1" == "01"); // bool(true) var_dump("10" == "1e1"); // bool(true) var_dump(null == false); // bool(true)My classmate runs an old XAMPP with PHP 7.4 and he says the first line gives true for him. So the same code gives different answers on different versions? That seems mad. Which rules does == actually follow, and is === really always the right choice, even when I compare a number from a form with a number in my code?
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.