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:

<?php
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

jQuery: Roll to Next Input

I was looking for a way to have an input, that when you change, would roll to the next input. The project I'm working on has a page based system, so each page has its own fieldset. When the last field is completed, I wanted it to automatically roll to the next page. I also wanted functionality for zip code, and phone number fields, that would roll to the next input after 5 digits on zip, or roll to the next piece of the phone number field.