Alex Rivera | Logout

Checking if a class is a subclass of another

Asked 2009-04-23T17:01:06.997
27

I want to check if a class is a subclass of another without creating an instance. I have a class that receives as a parameter a class name, and as a part of the validation process, I want to check if it's of a specific class family (to prevent security issues and such). Any good way of doing this?

Edit
Report

1 Answer

16

Check out is_subclass_of(). As of PHP5, it accepts both parameters as strings.

You can also use instanceof, It will return true if the class or any of its descendants matches.

answered 2009-04-23T17:20:24.000

Your Answer