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