Re: [RFC] Scalar Type Hinting With Casts (re-opening)
| From: | Alain Williams | Date: | Mon, 14 Jul 2014 17:01:49 +0000 |
| Subject: | Re: [RFC] Scalar Type Hinting With Casts (re-opening) | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75489@lists.php.net to get a copy of this message | ||
On Mon, Jul 14, 2014 at 12:25:22PM -0400, Anthony Ferrara wrote:
> IMHO, strict hints are dangerous in the context of PHP because PHP's
> types can change in unpredictable ways. A variable that was an integer
> can turn into a float through seemingly integer operations. Example:
> $a / $b * $b will result in a float unless $b divides $a (even though
> for sane values of $a and $b, it will be exactly representable as an
> int).
But if you have:
function foo(int $a) {
...
$a = 3 / 2;
}
What do you expect $a to contain ? I would suggest integer 1.
> And that also hints towards a benefit of adding a numeric hint as well
> (which will accept (and cast to) either an int or a float, exactly how
> is_numeric_string() does internally)... Which is something that may
> want to be considered for this RFC.
+1
--
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256 http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h>