Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

instanceof With Variables

<?php

$a = (object) ['b' => 1];
$b = new stdClass();

var_dump($a instanceof $b);
// true

?>

It is possible to compare the type of two objects with instanceof: PHP uses the class of the second operand, or the name of the class passed as a string.

Here, note that the cast operator (object) creates stdClass when applied to array.

See Also

PHP Features

Last updated: 09 November 2026