Implementing Custom Type Hinting
<?php
<?php
function many_hints($int, $flt, $str) {
if (!(is_integer($int))) {
trigger_error('$int is not of type integer', E_USER_ERROR);
}
if (!(is_float($flt))) {
trigger_error('$flt is not of type float', E_USER_ERROR);
}
if (!(is_string($str))) {
trigger_error('$str is not of type integer', E_USER_ERROR);
}
return ($int * $flt) . ' ' . $str;
}
echo '<p>', many_hints(1992, .042, 'dollars owed'), '</p>';
echo '<p>', many_hints('bob', 3, true), '</p>';
?>
Related examples in the same category