Re: is_a() vs. instanceof
| From: | Sean Coates | Date: | Thu, 12 Aug 2004 03:37:30 +0000 |
| Subject: | Re: is_a() vs. instanceof | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-12100@lists.php.net to get a copy of this message | ||
Dan Ostrowski wrote:
On Tuesday 10 August 2004 7:36 pm, Hans Lellelid wrote:The class must be loaded in order to perform an instanceof check! *snip*
Am I misunderstanding you?consider the following: <?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"; ?> outputs: $foo is_a Foo? yes $foo instanceof Foo? yes 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"; ?> outputs: $foo is_a Foo? no Fatal error: Class 'Foo' not found in /home/sean/phpdoc/scripts/tmp/is_a.php on line 8 --- I realize that is_a is deprecated, but it's more convenient in this situation. S