RE: [PHP-DEV] PHP Philosophy (was RE: [PHP-DEV] Scalar type hinting)
| From: | John Crenshaw | Date: | Fri, 02 Mar 2012 00:15:44 +0000 |
| Subject: | RE: [PHP-DEV] PHP Philosophy (was RE: [PHP-DEV] Scalar type hinting) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-58437@lists.php.net to get a copy of this message | ||
From: Simon Schick [mailto:simonsimcity@googlemail.com]
>
> Hi, John
>
> Therefore I think it would be easy to explain how a type-hint for scalar could work.
>
> You can explain it as saying that the following two functions should be end up in exactly the
> same result, whatever you're pasting into:
>
> function foo_one(scalar $bar) {}
>
> function foo_two($bar) {
> if (!is_scalar($bar))
> trigger_error("Catchable fatal error: Argument ? passed to ? must be a scalar, ?
>given,", E_RECOVERABLE_ERROR);
> }
Type hints that only ensure that something is a scalar are a non-starter for me. I'm not going
to waste my time on something like that. You're not going to get any better core support with
this, and you'll alienate support from a majority of userland as well. The average function
doesn't need "just a scalar, but any scalar will do". Most functions need something
specific, like a string, or a number. sqrt('foo') doesn't make any sense, it needs a
number, not just a scalar.
John Crenshaw
Priacta, Inc.