An instance only exists after it has been instantiated. So you can't know anything about an instance (== an object) beforehand. It's like knowing a person before they are born.

Maybe you mean you want to determine if class B is a subclass of class A. That's the same problem again. Even if PHP5 had a Class object (a la Java), you'd have to instantiate *it* in order to find the relationship between class A and class B. Prior to that point, you only have text strings to work with. I suppose you could search the text of the file for "extends FooBar" or something.

cheers,

Travis

Martin Towell wrote:
I have been playing with PHP5 and am liking it more and more. But I have one
question about "instanceof"

If you have something like this:

<?
class A { }
class B extends A { }
$x = new B;
if ($x instanceof B)  echo "B";
if ($x instanceof A)  echo "A";
?>

This would echo "BA". That's good, I understand that.

Now the question: Is it possible to determine if B is an instance of A
without instantiating it?

Thanks
Martin


-- Travis Low <mailto:[EMAIL PROTECTED]> <http://www.dawnstar.com>

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



Reply via email to