Re: [RFC] Scalar Type Hints v0.2
| From: | Marcio Almada | Date: | Fri, 16 Jan 2015 00:47:31 +0000 |
| Subject: | Re: [RFC] Scalar Type Hints v0.2 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80606@lists.php.net to get a copy of this message | ||
Stanislav Malyshev,
> I would rather have int $num for coercive typing - given that close to
> 100% of existing typed functions - namely internal functions - mean
> exactly that and are actually documented with this exact syntax.
> [...]
> As for strict, maybe it can be int! $num or something like that. I'm not
> exactly supporting it, but out of what I have seen this would make the
> most sense for me - it expresses the intent pretty clearly ("give me
> int! or else!" :) and does not conflict with existing stuff.
The hole point (at least for me) for being against `function bar(int
$num){}` to achieve type coercion is that the syntactic equivalent
code
function bar(array $numbers){} won't do any coercion - (array)
$numbers - because BC break would be too big to handle.
Having int|integer|bool|float|real|string as coercive type hints
while array is "strict" looks like an ugly hack (no pun intended).
2015-01-15 21:32 GMT-03:00 Stanislav Malyshev <smalyshev@gmail.com>:
> Hi!
>
>>> 1. Strict
>>> function bar(int $num){}
>>>
>>> 2. Lax
>>> function bar((int) $num){}
>
> I would rather have int $num for coercive typing - given that close to
> 100% of existing typed functions - namely internal functions - mean
> exactly that and are actually documented with this exact syntax. Yes,
> there are some functions that do strict, but those are in most cases are
> either close to bugs which nobody cares to fix since it's so narrow a
> case or some very special cases of some complex API where type matters
> for API-specific reasons.
>
> As for strict, maybe it can be int! $num or something like that. I'm not
> exactly supporting it, but out of what I have seen this would make the
> most sense for me - it expresses the intent pretty clearly ("give me
> int! or else!" :) and does not conflict with existing stuff.
>
> Putting it on the table as a brainstorming exercise.
>
> --
> Stas Malyshev
> smalyshev@gmail.com