RE: [PHP-DEV] [RFC] Scalar Type Hints
| From: | Zeev Suraski | Date: | Thu, 01 Jan 2015 12:41:06 +0000 |
| Subject: | RE: [PHP-DEV] [RFC] Scalar Type Hints | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80041@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Andrea Faulds [mailto:ajf@ajf.me]
> Sent: Wednesday, December 31, 2014 10:28 PM
> To: PHP Internals
> Subject: [PHP-DEV] [RFC] Scalar Type Hints
>
> Good evening,
>
> Parameter type hints for PHP’s scalar types are a long-requested feature
> for
> PHP. Today I am proposing an RFC which is a new attempt to add them to
> the language. It is my hope that we can finally get this done for PHP 7.
Andrea,
I like this draft too, and that's a first after countless proposals over the
last decade - so kudos! :)
My main feedback here are the discrepancies between this RFC's casting rules
and PHP's current built-in casting rules. Ideally, I'd like those to be
completely identical and not almost-identical.
Since we're talking about v7.0, we do have the option of making changes to
PHP's fundamental casting rules where appropriate (e.g. converting an array
to a string).
But that said, I think the way strings->numbers are handled - where they
accept only numeric strings as it would mean you can't use casting to an
int/float as an ultra-simple way to sanitize untrusted input. I would
change the † section from:
†Non-numeric strings not accepted. Numeric strings with trailing characters
are accepted, but produce a notice.
to
† Numeric strings with trailing characters and non-numeric strings are
accepted, but produce a notice.
- and apply it to both this RFC and the infrastructure convert_to_*(), so
that it applies across the board in PHP.
Zeev