PHP 7 interview question · Most asked
What is the difference between `==` and `===` in PHP?
Summary
== compares values after type juggling; === compares both value and type without conversion.
Longer Answer
'1' == 1 is true but '1' === 1 is false. For objects, == checks same class and equal properties, while === checks it's the same instance. Prefer === by default; it's clearer and avoids security bugs.
Key Points
==loose, converts types===strict, no conversion- Objects:
===means same instance
More most-asked PHP 7 questions
- What are typed properties in PHP 7.4?
- How do return type declarations work in PHP 7?
- What were the headline improvements of PHP 7.0 over PHP 5.6?
- Explain scalar type declarations and coercive vs strict mode in PHP 7.
- Explain the `Throwable`, `Error` and `Exception` hierarchy introduced in PHP 7.
- What are nullable types in PHP 7.1?
- What does the null coalescing operator `??` do, and how is it different from `isset()` with a ternary?
- What are arrow functions in PHP 7.4 and how do they differ from closures?