Re: is_a (WAS: Re: instanceof / __CLASS__ question [SOLVED])

From: Date: Tue, 31 Aug 2004 23:20:14 +0000
Subject: Re: is_a (WAS: Re: instanceof / __CLASS__ question [SOLVED])
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-195354@lists.php.net to get a copy of this message
Jason Barnett wrote:
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) ?
Hi, is_a is replaced by instanceof. I don't understand why you would need to check the class of $this anyways. Are you calling methods from classes that are not parent classes? If not, then you can be sure that $this is always a class in the hierarchy. Maybe a bit more code is in order to explain the problem. why not just do if ($this instanceof Test)? Greg

« previous php.general (#195354) next »