Checking Named Class Inheritance

I have been working on a new cache implementation for the Symfony2 framework, and I needed a way to check if a named class inherited a given interface , so i wrote the following:

function classInherits( $class, $inherit ) {
	if( is_object( $class ) ) {
		return ( $class instanceof $inherit );
	} elseif( is_string( $class ) ) {
		return (bool) in_array( $inherit, class_implements( $class ) );

	throw new Exception( "First value must be the name of a valid class, or an instance of one." );

Hope this helps!

Share This:

Related Posts

Creating a Chrome Extension with NextJS

So, you've delved into writing your own Chrome extension. Maybe you've even already made one, but you still have a question: How can I use more current technology to to this? Well, as it turns out, it only takes a few extra steps!