Re: Adding "numeric" type hint

From: Date: Wed, 29 Apr 2015 21:23:39 +0000
Subject: Re: Adding "numeric" type hint
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-86030@lists.php.net to get a copy of this message
Hi Francois, On Wed, Apr 29, 2015 at 7:03 PM, François Laupretre <francois@php.net> wrote: > > De : yohgaki@gmail.com [mailto:yohgaki@gmail.com] De la part de Yasuo > > Ohgaki > > > > External data can have any form of numbers. > > Current PHP can handle them as "string". However PHP7's type hint cannot > > handle numeric data well because it only has "int" and "float" hints. > > > > http://3v4l.org/6J0bZ > > I don't understand the error message. PHP 7 is supposed to accept numeric > strings for 'int'. Is it too big for an int ? In this case, it is a > conversion failure, the error message is wrong and should be replaced. > About 32/64 bit integers, this is another subject that was partially > hidden, as many others, by the STH war. > 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 } issue is resolved. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net

« previous php.internals (#86030) next »