Re: is_a() against instanceof

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----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-----

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux