Re: is_a() against instanceof
| From: | Christian Stadler | Date: | Sun, 20 Mar 2005 21:04:16 +0000 |
| Subject: | Re: is_a() against instanceof | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-211148@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jason Barnett schrieb:
> Nice suggestion! But I wonder... would it perhaps be better to use the
> && operator instead of the AND operator? That way in case you are
> trying to do an assignment PHP won't bother to check instanceof if the
> class_exists() fails.
>
> if (class_exists($class) && $cls instanceof $class)
> {
>
> }
mmh ... instanceof isn't listed at
http://www.php.net/manual/en/language.operators.php#language.operators.precedence
so I'm not 100% sure. But neither
php -r "var_dump(class_exists('foobar') AND $a instanceof foobar);"
nor
php -r "var_dump(class_exists('foobar') AND ($a instanceof foobar));"
triggered an error on the commandline. So I guess, both && and AND
should work.
Regards,
Christian Stadler
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCPeVQ9250Hcbf/3IRAg6rAJ96A/iBzkDU1X3cCOFWo/waV1y3ywCfSbIF
S4JU3lo66WnPw5y8q3qMVSU=
=bRQK
-----END PGP SIGNATURE-----