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 Expect Objects

PHP used to report a fatal error when provided with a value that is not an object. After PHP 7.3, it would return false in such case, and not break the execution.

PHP code

<?php

var_dump(null instanceof Countable);

function foo() : ?X { /**/ }
var_dump(foo() instanceof Countable); // possible error when foo() returns null

?>

Before

PHP Fatal error:  instanceof expects an object instance, constant given 

Fatal error: instanceof expects an object instance, constant given 

After

bool(false)

PHP version change

This behavior changed in 7.3.

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat