Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
OOP

instanceof in PHP

Check an object’s type with instanceof before calling type-specific APIs.

instanceof in PHP — a practical guide to PHP instanceof with clear examples you can reuse in real projects.

OOP Tutorial Series (35/65). Prefer one article? Read the complete OOP tutorial.

Short description

`instanceof` works with classes and interfaces. Prefer type hints when possible instead of frequent runtime checks.

instanceof

function dump($value): void {
    if ($value instanceof DateTimeInterface) {
        echo $value->format('c');
    }
}

Leave a reply

Your email address will not be published. Required fields are marked *