note 89100 modified in function.is-callable by danbrown
| From: | danbrown@php.net | Date: | Sun, 22 Feb 2009 00:39:32 +0000 |
| Subject: | note 89100 modified in function.is-callable by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150945@lists.php.net to get a copy of this message | ||
Revised function with static support:
<?php
/**
* 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;
}
?>
--was--
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;
}
http://php.net/manual/en/function.is-callable.php