note 89100 added to function.is-callable
| From: | juand at softwarecubes dot com | Date: | Sat, 21 Feb 2009 19:39:38 +0000 |
| Subject: | note 89100 added to function.is-callable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150928@lists.php.net to get a copy of this message | ||
Revised function with static support:
/**
* The is_callable php function only considers methods declared in the class itself, and ignores
the parent's.
* This version considers all of the hierarchy.
*
* @param (string|Object) $class_name
* @param string $method_name
* @param bool $static the method being tested is static.
*/
public static function isCallable( $class_name, $method_name, $static = false ){
if( !is_string( $class_name ) ){
$class_name = get_class( $class_name );
}
// Define Callable
if( $static ){
$callable = "{$class_name}::{$method_name}";
}else{
$callable = array( $class_name, $method_name );
}
// Check class itself
if( @is_callable( $callable ) === true ){
if( $method_name == 'setEmailAddressTypeHash' ) {
ErrorHandler::preDump($callable);
}
return true;
}
// Check all parents
while( $parent_class = get_parent_class( $class_name ) ){
if( @is_callable( $callable ) === true ){
return true;
}
$class_name = $parent_class;
}
return false;
}
----
Server IP: 66.207.199.35
Probable Submitter: 96.49.181.214
----
Manual Page -- http://www.php.net/manual/en/function.is-callable.php
Edit -- https://master.php.net/note/edit/89100
Del: integrated -- https://master.php.net/note/delete/89100/integrated
Del: useless -- https://master.php.net/note/delete/89100/useless
Del: bad code -- https://master.php.net/note/delete/89100/bad+code
Del: spam -- https://master.php.net/note/delete/89100/spam
Del: non-english -- https://master.php.net/note/delete/89100/non-english
Del: in docs -- https://master.php.net/note/delete/89100/in+docs
Del: other reasons-- https://master.php.net/note/delete/89100
Reject -- https://master.php.net/note/reject/89100
Search -- https://master.php.net/manage/user-notes.php