note 17879 added to function.get-parent-class
| From: | markboylan at hotmail dot com | Date: | Mon, 31 Dec 2001 04:01:35 +0000 |
| Subject: | note 17879 added to function.get-parent-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-24010@lists.php.net to get a copy of this message | ||
Not only that, you can use it to determine an object's heritage by calling it repetedly. This
comes in handy when you want to handle a group of objects that you expect to be derived from a
common base class :
// Returns true if $object is derived from $classname
function is_type_of( &$object, $classname )
{
if ( ! is_object( $object ) )
return false;
$thisclass = get_class( $object );
while ( $thisclass )
{
if ( ! strcasecmp( $thisclass, $classname ) )
return true;
$thisclass = get_parent_class( $thisclass );
}
return false;
}
--
http://www.php.net/manual/en/function.get-parent-class.php
http://master.php.net/manage/user-notes.php?action=edit+17879
http://master.php.net/manage/user-notes.php?action=delete+17879
http://master.php.net/manage/user-notes.php?action=reject+17879