Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The === operator, known as the strict equality or identity operator, evaluates whether two operands are identical in both value and data type without performing implicit type coercion (type juggling). If the operands are of different data types, the PHP engine immediately evaluates the expression to false.

Syntax

$operand1 === $operand2
The expression returns a boolean value: true if the operands are strictly identical, and false otherwise.

Evaluation Mechanics by Data Type

The behavior of the === operator varies depending on the underlying types of the operands being compared:

1. Scalar Types (Integers, Floats, Strings, Booleans)

For scalar values, the operator checks the internal type flag of the zval (Zend value) container. If the type flags match, it compares the underlying values. For integers, strings, and booleans, the values must be exactly identical. For floating-point numbers, PHP applies standard IEEE 754 rules rather than a raw memory byte comparison. Under these rules, 0.0 and -0.0 are considered strictly equal despite differing sign bits, while NAN is never strictly equal to anything, including itself.
var_dump(42 === 42);      // bool(true)  - Same type (int), same value
var_dump(42 === "42");    // bool(false) - Type mismatch (int vs string)
var_dump(42 === 42.0);    // bool(false) - Type mismatch (int vs float)
var_dump(0.0 === -0.0);   // bool(true)  - IEEE 754 float comparison rules
var_dump(NAN === NAN);    // bool(false) - IEEE 754 float comparison rules

2. Arrays

When comparing arrays, === evaluates to true only if both arrays satisfy all of the following conditions:
  • They contain the exact same number of elements.
  • They contain the exact same key-value pairs.
  • The keys are defined in the exact same insertion order.
  • The values for corresponding keys are strictly identical (===).
$a = ["x" => 1, "y" => 2];
$b = ["x" => 1, "y" => 2];
$c = ["x" => 1, "y" => "2"];
$d = ["y" => 2, "x" => 1];

var_dump($a === $b); // bool(true)  - Identical structure, types, and order
var_dump($a === $c); // bool(false) - Value type mismatch at key 'y' (int vs string)
var_dump($a === $d); // bool(false) - Order mismatch (same key-value pairs, different sequence)

3. Objects

For object comparison, the === operator does not compare the internal properties or class types of the objects. Instead, it evaluates to true if and only if both operands are references pointing to the exact same object instance in memory (object identity).
class Node {
    public $value;
}

$obj1 = new Node();
$obj1->value = 10;

$obj2 = new Node();
$obj2->value = 10;

$obj3 = $obj1;

var_dump($obj1 === $obj2); // bool(false) - Same class and properties, but different instances
var_dump($obj1 === $obj3); // bool(true)  - Both variables reference the same instance
The logical negation of the strict equality operator is the strict inequality operator, represented by !==. It returns true if the operands differ in either value or data type.
Master PHP with Deep Grasping Methodology!Learn More