Re: Adding "numeric" type hint
| From: | Yasuo Ohgaki | Date: | Wed, 29 Apr 2015 21:27:59 +0000 |
| Subject: | Re: Adding "numeric" type hint | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-86032@lists.php.net to get a copy of this message | ||
Hi Francois,
On Thu, Apr 30, 2015 at 6:23 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> Allowing any forms of int/float as string(and GMP) for weak mode int/float
> type hint
> would be alternative resolution for this issue. I think it's better than
> "numeric" type
> hint.
>
> It seems current weak/strict type hint difference is
> - weak: allow conversion, force the type
> - strict: not allow conversion, force the type
>
> If weak mode allows this
>
> function foo(int $val) {
> // $val became "int" if value fits for int
> // otherwise "integer string" or "gmp" object accepted
> // anything else is error
> }
>
I forgot to mention float. 32 bit machines uses float as int extensively.
So it should be
function foo(int $val) {
// $val became "int" if value fits for int
// (allow float value that is integer form)
// otherwise "integer string" or "gmp" object accepted
// anything else is error
}
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net