Re: PHP5 - instanceof
| From: | Travis Low | Date: | Thu, 13 May 2004 04:42:19 +0000 |
| Subject: | Re: PHP5 - instanceof | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-186072@lists.php.net to get a copy of this message | ||
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:travis@dawnstar.com> <http://www.dawnstar.com>