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');
}
}