Re: [RFC] Strict type hints (parameter and return value)
| From: | Christian Schneider | Date: | Thu, 17 Apr 2008 15:41:39 +0000 |
| Subject: | Re: [RFC] Strict type hints (parameter and return value) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-37074@lists.php.net to get a copy of this message | ||
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
- Chris