So in my blog series I try to cover all additions to PHP trunk so I have to mention scalar type hints.
<?php function print_float(float $f) { echo $f."\n"; } for ($i = 1; $i < 5; $i++) { print_float( $i / 3 ); } ?>0.33333333333333
0.66666666666667
Catchable fatal error: Argument 1 passed to print_float() must be of the type double, integer given, called in typehints.php on line 7 and defined in typehints.php on line 2
Is expected behavior in PHP's trunk. If you want such a thing to work please use the numeric type hint.
In case that wasn't enought fun: There's more!
<?php
function handle_result(int $i) {
echo $i."\n";
} [Read more...]