Jason Barnett wrote:
Christian Stadler wrote:
Eli schrieb:
- ($cls instanceof ClassName) *requires* from ClassName to be declared,
and generates a fatal error when ClassName is not declared.
How about
if (class_exists('ClassName') AND $cls instanceof ClassName)
{
...
}
Regards,
Christian Stadl
-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_exist
Christian Stadler wrote:
> Eli schrieb:
>
>>>- ($cls instanceof ClassName) *requires* from ClassName to be declared,
>>>and generates a fatal error when ClassName is not declared.
>
> How about
> if (class_exists('ClassName') AND $cls instanceof ClassName)
> {
>...
> }
>
> Regards,
> Christi
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Eli schrieb:
> - ($cls instanceof ClassName) *requires* from ClassName to be declared,
> and generates a fatal error when ClassName is not declared.
How about
if (class_exists('ClassName') AND $cls instanceof ClassName)
{
...
}
Regards,
Christia
Jason Barnett wrote:
Eli wrote:
...
- is_a($cls,"ClassName") *doesn't require* from ClassName to be
declared, and return false when ClassName is not declared.
...
Try is_subclass_of()
http://php.net/manual/en/function.is-subclass-of.php
is_subclass_of() is not exactly like is_a(), in that it will
Eli wrote:
...
> - is_a($cls,"ClassName") *doesn't require* from ClassName to be
> declared, and return false when ClassName is not declared.
...
Try is_subclass_of()
http://php.net/manual/en/function.is-subclass-of.php
--
Teach a man to fish...
NEW? | http://www.catb.org/~esr/faqs/smart-quest
6 matches
Mail list logo