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

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



Reply via email to