Dave Ingram wrote:
I remember that multiple signatures was said to have a possible very
difficult implementation. However, a similar behaviour can be achieved by
some instanceof().
I thought it probably would be awkward, but we do already have some type
hinting that can also be accomplished with instanceof() -- this is just
an extension of that idea. Although it's not my idea as such!
instance of is handy however it isn't the cleanest; consider:
public static function parseByte( $var )
{
$testPassed = false;
if( $var instanceof Number ) {
$var = $var->byteValue();
$testPassed = true;
} if( $var instanceof String ) {
$var = $var->__toString();
}
if( !$testPassed && is_numeric( $var ) ) {
$var = 0 + $var;
$testPassed = true;
}
if( $testPassed && Byte::MIN_VALUE <= $var && Byte::MAX_VALUE >=
$var ) {
return $var;
}
throw new NumberFormatException();
}
could be:
public static function parseByte( Number $var )
{
return $var->byteValue();
}
public static function parseByte( String $var )
{
if( is_numeric( $var = $var->__toString() ) ) {
$var = 0 + $var;
if( Byte::MIN_VALUE <= $var && Byte::MAX_VALUE >= $var ) {
return $var;
}
}
throw new NumberFormatException();
}
mini-use-case but shows how useful it would be..
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php