Hi Derick,
Derick Rethans wrote:
On Mon, 12 Oct 2015, Andrea Faulds wrote:
you'll get the following error:
Fatal error: Uncaught TypeError: Return value of foo() must be an instance
of integer, integer returned
<snip>
you'd get this:
Fatal error: Uncaught TypeError: Return value of foo() must be an instance
of boolean, boolean returned
What about double vs float? Another common combination.
Oh yeah, that's a bit of an issue. Since I changed it, PHP 7 doesn't say
'double' in its type error messages any more, but there's still going to
be people who'd expect that to work. So, my patch to reserve and produce
errors includes 'double'.
This is also an issue for argument typehints:
Exactly the same issue, yes. I just used return types for my examples,
sorry if that was unclear.
TypeError: Argument 1 passed to foo() must be an instance of integer,
integer given, called in /tmp/scalar.php on line 7 in /tmp/scalar.php on
line 3
(I also think, this reads odd with two times "in <filename> on line
<x>")
It does. Could be improved slightly by the addition of a comma before
the second 'in'.
for:
<?php
declare(type=strict);
function foo(integer $a) { }
foo(42);
?>
To avoid confusion, I would like it if we reserve 'integer' and 'boolean'
alongside 'int' and 'bool', and make them produce an error if used.
With a parse error mentioning 'illegal token' or something like that?
Yeah. My current patch does this:
./sapi/cli/php -r 'function foo(): long {}'
Fatal error: 'long' is not a valid type hint, use 'int' instead in
Command line code on line 1
If you try to use it as a the name of a class/interface/trait, it
produces the usual error for reserved class name.
Well, that's what we have RCs for. And there are a few more coming up!
Yes, perhaps I shouldn't give up just yet.
I'd find that nannying :)
It *is* a bit annoying, especially if you actually intended to have a
class by that name.
I'd prefer reservation of integer and boolean, but a better error
message is okay too. I'd go with something like:
Fatal error: Uncaught TypeError: Return value of foo() must be an instance of
class boolean, scalar boolean returned
That sounds good, albeit a little verbose.
Thanks!
--
Andrea Faulds
http://ajf.me/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php