Re: is_a() vs. instanceof
| From: | Al Baker | Date: | Thu, 12 Aug 2004 09:58:54 +0000 |
| Subject: | Re: is_a() vs. instanceof | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-12115@lists.php.net to get a copy of this message | ||
I agree, that's the exact behavior I would like as well and what most
people would expect.
Al
On Wed, 2004-08-11 at 23:52 -0400, Hans Lellelid wrote:
> Alan Knowles wrote:
>
> > I think he's referening to something like this (which is common in pear):
> >
> > $x = $someobj->somemethod();
> > if ($x instanceOf PEAR_Error) {
> > .......
> > }
> >
> > while that code is redundant in the case of exceptions, it is still a
> > valid situation.. that $x may be a valid return, and PEAR_Error was
> > never loaded..
>
>
> Yup, that's exactly what I'm talking about.
>
> I want to be able to do this:
>
> if ($db instanceof DBPostgres) {
> /// do something funky specific to Postgres
> }
>
> If My DB adapter is DBMySQL, I don't want to load the DBPostgres adapter
> just so I can test whether my object is of that type ...
>
> and checking first whether class_exists('DBPostgres') just seems kinda
> kludgy & straying from the "problem domain" ... especially since $db
> instanceof DBPostgres would *always* be false if DBPostgres isn't loaded.
>
> Hans
>