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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to