ah yes, of course "instanceof" means you're working with an instance of an
class - <slaps forehead>

Pity there's no equivalent for classes :( oh well, I'll just have
instantiate the class first then do the checking.

Thanks
Martin

> -----Original Message-----
> From: Travis Low [mailto:[EMAIL PROTECTED]
> Sent: Thursday, 13 May 2004 2:42 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] PHP5 - instanceof
> 
> 
> 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

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

Reply via email to