Greg Beaver wrote:
Hi,
I'm not sure I understand why you would use instanceof on $this. Try this code:
Kind of complicated (so probably not the best way) but I have objects I'm creating with a factory method - and all of these objects *should* be extending a parent class. It's in the parent class where I'm using $this instanceof __CLASS__ and alternatives are welcome. I thought is_a was being deprecated (correct me if I'm wrong) ?
instanceof defines whether an object is or descends from a class (like is_a()).
If you want to check whether $this is the Test class or a descendant class, the simplest way I know is
if (get_class($this) == 'Test')
Yes, it probably makes more sense to do it this way. Reflections would be overkill, all I need is to test for inheritance.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php