Это как-то возможно? если нет, то посоветуй красивую реализацию данной проверки. Вообще хотелось бы обзавестись красивым методом валидации аргументов самописных методов, но пока ничего сам не придумал

function fname(array $args, $arg2 ) {
if (!is_string($arg2))
throw new Exception(...);
}
<?php
define( 'TYPEHINT_PCRE' ,'/^Argument (\d)+ passed to (?:(\w+)::)?(\w+)\(\) must be an instance of (\w+), (\w+) given/' );
class Typehint
{
private static $Typehints = array(
'boolean' => 'is_bool',
'integer' => 'is_int',
'float' => 'is_float',
'string' => 'is_string',
'resrouce' => 'is_resource'
);
private function __construct() {}
public static function initializeHandler()
{
set_error_handler('Typehint::handleTypehint');
return TRUE;
}
private static function getTypehintedArgument( $ThBackTrace, $ThFunction, $ThArgIndex, &$ThArgValue )
{
foreach( $ThBackTrace as $ThTrace )
{
if( isset($ThTrace['function']) && $ThTrace['function'] == $ThFunction )
{
$ThArgValue = $ThTrace['args'][$ThArgIndex - 1];
return TRUE;
};
};
return FALSE;
}
public static function handleTypehint( $ErrLevel, $ErrMessage )
{
if( $ErrLevel == E_RECOVERABLE_ERROR )
{
if( preg_match( TYPEHINT_PCRE, $ErrMessage, $ErrMatches ) )
{
list( $ErrMatch, $ThArgIndex, $ThClass, $ThFunction, $ThHint, $ThType ) = $ErrMatches;
if( isset( self::$Typehints[$ThHint] ) )
{
$ThBacktrace = debug_backtrace();
$ThArgValue = NULL;
if( self::getTypehintedArgument( $ThBacktrace, $ThFunction, $ThArgIndex, $ThArgValue ) )
{
if( call_user_func( self::$Typehints[$ThHint], $ThArgValue ) )
{
return TRUE;
};
};
};
};
};
return FALSE;
}
}
Typehint::initializeHandler();
function test( string $arg1, integer $arg2 ) { echo $arg1; }
//function testinteger(integer $integer) { echo $integer; }
//function testfloat(float $float) { echo $float; }
test('test1', 123);
test('test2','test');
?>