ID: 29736 Updated by: [EMAIL PROTECTED] Reported By: hans at velum dot net -Status: Open +Status: Bogus Bug Type: Feature/Change Request -Operating System: All +Operating System: * PHP Version: 5.0.1 New Comment:
Can't reproduce: [EMAIL PROTECTED] /usr/src/PHP_5_0 $ php -r 'function __autoload($name) { var_dump($name); } $x = NULL; var_dump($x instanceof test);' make: `sapi/cli/php' is up to date. string(4) "test" Fatal error: Class 'test' not found in Command line code on line 1 [EMAIL PROTECTED] /usr/src/PHP_5_0 $ php -r 'function __autoload($name) { var_dump($name); eval("class $name {}");} $x = NULL; var_dump($x instanceof test);' make: `sapi/cli/php' is up to date. string(4) "test" bool(false) So the problem lies in unserialize() -> other bug Previous Comments: ------------------------------------------------------------------------ [2004-08-18 16:31:23] hans at velum dot net Description: ------------ [pasted from messages on internals@ list] I like the new $obj instanceof ClassName way of checking class / interface types, .... but this method does have one major drawback compared to the old is_a() approach: The class must be loaded in order to perform an instanceof check! There are many situations where you do not want to have to load every class to see whether a returned object is a class of that type. In particular for driver classes, the current model requires loading *every* possible driver in order to check to see which type of class was returned. is_a() works great, but has been deprecated and is now generating E_STRICT errors. Reproduce code: --------------- [conributed by Sean Coates on internals@ list] <?php class Foo {} $foo = unserialize('O:3:"Foo":0:{}'); echo '$foo is_a Foo? '. (is_a($foo, 'Foo') ? 'yes' : 'no') ."\n"; echo '$foo instanceof Foo? '. ($foo instanceof Foo ? 'yes' : 'no') ."\n"; ?> ---- and ---- <?php //class Foo {} $foo = unserialize('O:3:"Foo":0:{}'); echo '$foo is_a Foo? '. (is_a($foo, 'Foo') ? 'yes' : 'no') ."\n"; echo '$foo instanceof Foo? '. ($foo instanceof Foo ? 'yes' : 'no') ."\n"; ?> Expected result: ---------------- $foo is_a Foo? yes $foo instanceof Foo? yes ---- and ---- $foo is_a Foo? no $foo instanceof Foo? no Actual result: -------------- $foo is_a Foo? yes $foo instanceof Foo? yes ---- and ---- $foo is_a Foo? no Fatal error: Class 'Foo' not found in /home/sean/phpdoc/scripts/tmp/is_a.php on line 8 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29736&edit=1