> ## 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.

# PHP Instanceof

The `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.

```php theme={"dark"}
$result = $object instanceof ClassName;
```

## Operand Specifications

* **Left Operand (`$object`):** The variable being evaluated. If the evaluated variable is not an object (e.g., a string, integer, or `null`), `instanceof` safely evaluates to `false` without 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 to `true` under any of the following conditions:

1. **Exact Match:** The left operand is an instance of the exact class specified by the right operand.
2. **Inheritance:** The left operand is an instance of a class that extends the right operand's class at any point in the inheritance tree.
3. **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

```php theme={"dark"}
interface Runnable {}
class BaseProcess implements Runnable {}
class BackgroundProcess extends BaseProcess {}

$process = new BackgroundProcess();

// 1. Exact Match
$process instanceof BackgroundProcess; // true

// 2. Inheritance Match
$process instanceof BaseProcess;       // true

// 3. Interface Match
$process instanceof Runnable;          // true

// 4. Non-Object Evaluation
$nonObject = "BackgroundProcess";
$nonObject instanceof BaseProcess;     // false
```

## Dynamic Evaluation and Right Operand Variations

The right operand accepts dynamic values, but strict syntax rules apply regarding string literals.

```php theme={"dark"}
$targetClass = 'BackgroundProcess';
$otherProcess = new BaseProcess();

// Using a string variable containing the class name
$process instanceof $targetClass;  // true

// Using another object instance (checks if $process is an instance of $otherProcess's class)
$process instanceof $otherProcess; // true

// SYNTAX ERROR: Direct string literals are not permitted
// $process instanceof 'BackgroundProcess'; 

// PHP 8.0+: Arbitrary expressions are allowed if wrapped in parentheses
$process instanceof ('Background' . 'Process'); // true
```

## Operator Precedence and Negation

The `instanceof` 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.

```php theme={"dark"}
// Valid negation: evaluates natively as !($process instanceof Runnable)
$isNotRunnable = !$process instanceof Runnable;

// Equivalent expression using parentheses for explicit readability
$isNotExplicit = !($process instanceof Runnable);
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor PHP Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
