Type Hinting in PHP7
I’m happy that PHP7 has finally been released, I’ve been wanting to correctly return type hint for such a long time. You can now do this comfortably:
<?php
declare(strict_types=1);
function getAge(int $age) : int {
return $age;
}
echo var_dump(getAge(43));
?>
But more usefully, you can type hint interfaces to guarantee the classes you get returned (which is actually far, far more useful and beneficial).
Found this useful? Everything here is free and stays that way. If it saved you an afternoon, you can buy me a coffee.