On 13 Jul 2014, at 02:57, Andrea Faulds <a...@ajf.me> wrote:

> The RFC is here: https://wiki.php.net/rfc/scalar_type_hinting_with_cast
> 
> A pull request is here: https://github.com/php/php-src/pull/717

I just updated the patch and RFC to include overflow safety for the integer 
type hint. This means that the following code is an error:

    function foo(int $a) {}
    foo(‘8493284029384029384028409304249230894’);

This is actually a level of safety you couldn’t get with any other proposal. If 
you explicitly cast with (int) it will silently saturate/cap the integer (data 
is lost), and zend_parse_parameters will silently saturate or truncate 
(depending on the function).

This is consistent with passing a float. Were I to do the following, it was 
already an error in the proposal:

    function foo(int $a) {}
    foo(8493284029384029384028409304249230894.0);

--
Andrea Faulds
http://ajf.me/





--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to