TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
instanceof operator is a binary type operator used to determine if a given variable is an instantiated object of a specific class, a descendant of that class, or an implementer of a specified interface. It evaluates the object’s inheritance hierarchy at runtime and returns a boolean value.
Operand Specifications
- Left Operand (
$object): The variable being evaluated. If the evaluated variable is not an object (e.g., a string, integer, ornull),instanceofsafely evaluates tofalsewithout emitting a warning or type error. - Right Operand (
ClassName): The target type identifier. This can be an unquoted class or interface name, an object instance, or a variable containing a string of the fully qualified class/interface name.
Resolution Rules
The operator evaluates totrue under any of the following conditions:
- Exact Match: The left operand is an instance of the exact class specified by the right operand.
- Inheritance: The left operand is an instance of a class that extends the right operand’s class at any point in the inheritance tree.
- Polymorphism (Interfaces): The left operand is an instance of a class (or extends a class) that implements the interface specified by the right operand.
Syntax Mechanics and Evaluation
Dynamic Evaluation and Right Operand Variations
The right operand accepts dynamic values, but strict syntax rules apply regarding string literals.Operator Precedence and Negation
Theinstanceof operator has higher precedence than the logical NOT operator (!). When negating an instanceof expression, the type check evaluates first, followed by the negation. While wrapping the expression in parentheses is a common practice for human readability, the unparenthesized version is perfectly valid and functionally correct.
Master PHP with Deep Grasping Methodology!Learn More





