Re: [RFC] Scalar Type Hinting With Casts (re-opening)
| From: | Andrea Faulds | Date: | Fri, 25 Jul 2014 01:16:58 +0000 |
| Subject: | Re: [RFC] Scalar Type Hinting With Casts (re-opening) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-76083@lists.php.net to get a copy of this message | ||
On 13 Jul 2014, at 02:57, Andrea Faulds <ajf@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/