note 101429 added to reflectionclass.getparentclass

From: Date: Thu, 16 Dec 2010 09:26:38 +0000
Subject: note 101429 added to reflectionclass.getparentclass
Groups: php.notes 
Request: Send a blank email to php-notes+get-174972@lists.php.net to get a copy of this message
Here is a "replacement" for is_a that will additionally look both into the extended classes and in the implemented interfaces /** * Check if a class extends or implements a specific class/interface * @param string $search The class or interface name to look for * @param string $className The class name of the object to compare to * @return bool */ function IsExtendsOrImplements( $search, $className ) { $class = new ReflectionClass( $className ); if( false === $class ) { return false; } do { $name = $class->getName(); if( $search == $name ) { return true; } $interfaces = $class->getInterfaceNames(); if( is_array( $interfaces ) && in_array( $search, $interfaces )) { return true; } $class = $class->getParentClass(); } while( false !== $class ); return false; } ---- Server IP: 195.26.5.11 Probable Submitter: 158.169.9.14 ---- Manual Page -- http://www.php.net/manual/en/reflectionclass.getparentclass.php Edit -- https://master.php.net/note/edit/101429 Del: integrated -- https://master.php.net/note/delete/101429/integrated Del: useless -- https://master.php.net/note/delete/101429/useless Del: bad code -- https://master.php.net/note/delete/101429/bad+code Del: spam -- https://master.php.net/note/delete/101429/spam Del: non-english -- https://master.php.net/note/delete/101429/non-english Del: in docs -- https://master.php.net/note/delete/101429/in+docs Del: other reasons-- https://master.php.net/note/delete/101429 Reject -- https://master.php.net/note/reject/101429 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174972) next »