Edit report at https://bugs.php.net/bug.php?id=55246&edit=1
ID: 55246 User updated by: x11 at arturaz dot net Reported by: x11 at arturaz dot net Summary: instanceof does not complain even if class is never defined Status: Bogus Type: Bug Package: Compile Failure Operating System: Ubuntu Linux PHP Version: 5.3.6 Block user comment: N Private report: N New Comment: Yeah, autoloader should try to load the class and then, if unsuccessful - fail. Seriously. I know that it's cool to have funny glitches in PHP like FOO reverting to 'FOO' if it's undefined, but this? Previous Comments: ------------------------------------------------------------------------ [2011-07-20 04:55:24] paj...@php.net Think of autoloader, or other related tests. A warning or error here is not welcome. ------------------------------------------------------------------------ [2011-07-20 04:34:57] x11 at arturaz dot net How it's possibly useful to test if object is an instance of class which is not even defined? ------------------------------------------------------------------------ [2011-07-20 04:33:47] paj...@php.net That's the exact idea of instanceof to test something without getting noises. ------------------------------------------------------------------------ [2011-07-20 04:31:42] x11 at arturaz dot net Description: ------------ PHP does not complain if you check for non-existant class with instanceof. This provides space for subtle errors, like checking for DateRange when only Date_Range class is defined. Test script: --------------- <?php echo PHP_VERSION . "\n"; error_reporting(E_ALL); class Foo {} $a = new Foo; // Notice that Bar class is never defined, however PHP does not complain about missing class. if ($a instanceof Bar) { echo "Should be an error\n"; } else { echo "PHP fail\n"; } Expected result: ---------------- Compiler error thrown saying that Bar was not found. Actual result: -------------- Nothing happens. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55246&edit=1