Re: Re: [RFC] Strict type hints (parameter and return value)
| From: | Pierre Joye | Date: | Thu, 17 Apr 2008 15:59:55 +0000 |
| Subject: | Re: Re: [RFC] Strict type hints (parameter and return value) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-37076@lists.php.net to get a copy of this message | ||
Hi Christian,
On Thu, Apr 17, 2008 at 5:41 PM, Christian Schneider
<cschneid@cschneid.com> wrote:
> Felipe Pena wrote:
> > Well, thinking better about the behavior of type hinting, i decided to
> > change the proposal for strict type. I.e. don't accept numeric string
> > as an intenger, etc.
>
> While it is now consistent with is_int() it means we end up with strict
> but also stupid interfaces and hence lots of silly type conversions in
> application code using such a function.
> This is especially annoying as you normally have very few
> implementations of a function but lots of code calling it.
>
> You basically 'progressed' from
> function foo($x) { $x = (int)$x; ... } # One place where type is
> ensured or converted
> foo(42);
> foo(CONSTANT_42);
> foo($x);
> foo($db->x);
> to
> function foo(int $x) { ... }
> foo(42);
> foo((int)CONSTANT_42); # If you are not 100% about type
> foo((int)$x); # If you are not 100% about type
> foo((int)$db->x); # DBs normally return strings
You slowly understand the idea behind strict type hinting, you should
add these examples to the wiki ;-)
More seriously, it should be about time to stop to argue about why you
consider it useless, not the PHP way, too many to write, usw... But
to consider the proposal and the patch on their own and if the feature
will be added, is it the way we like to have it or how can it be
improved (keeping the goal in mind).
Whether PHP will have it or not is not yet decided, as far as I can
say. But I really like to have it (I don't feel like explaining again
why I like it is worth the bandwidth :)
Cheers,
--
Pierre
http://blog.thepimp.net | http://www.libgd.org