On 12/10/15 21:23, Andrea Faulds wrote: > Hi, > > As PHP 7 currently is, if you write this: > > public function foo(): integer { > return 12; > } > $bar = foo(); > > you'll get the following error: > > Fatal error: Uncaught TypeError: Return value of foo() must be an > instance of integer, integer returned > > Similarly, if you were to write this: > > public function foo(): boolean { > return true; > } > $bar = $foo(); > > you'd get this: > > Fatal error: Uncaught TypeError: Return value of foo() must be an > instance of boolean, boolean returned > ... > Alongside or instead of that, though, we can do two other things to make > this situation better. > > First, we could make type error messages use 'int' and 'bool'. This > feels somewhat wrong to me since integer and Boolean are the proper > English names for the types. But we do use the short names in some other > places, like var_dump, so this isn't so bad. This way, we get this > slightly clearer error: > > Fatal error: Uncaught TypeError: Return value of foo() must be an > instance of integer, int returned > > Second, we could add a helpful note to the TypeError message when the > type hint is for a class named 'integer' or 'boolean' and the value > passed was an integer or Boolean, respectively. My patch (based on > Anthony's original) for the earlier Scalar Type Hinting with Cast RFC > did this. This would make things even clearer: > > Fatal error: Uncaught TypeError: Return value of foo() must be an > instance of integer, int returned (did you mean to use the type hint > 'int'?) > > Even if we can't reserve the names, I hope we can do the two other > suggestions in time for release.
Additionally, we could say "instance of class ...". -- Regards, Mike -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php