Check Class Inheritance

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Check Class Inheritance

Post by aliasxneo »

I have a function which I need to check if an object inherits a certain class and if so act on it. I'm not sure of PHP has a native function to check if the class extends another class and to get that class name which is why I'm asking here. If not can anyone suggest a way to determine if an object is extending a certain class? Thanks.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Check Class Inheritance

Post by Christopher »

instanceof
(#10850)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Check Class Inheritance

Post by Chris Corbyn »

Yep, as arborint suggests, in PHP5 you can use the "instanceof" operator, and in PHP4 you can use the is_a() function.
Post Reply