Re: is_a() vs. instanceof

From: Date: Thu, 12 Aug 2004 03:52:16 +0000
Subject: Re: is_a() vs. instanceof
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-12101@lists.php.net to get a copy of this message
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

« previous php.internals (#12101) next »