> Am 3.6.2016 um 12:28 schrieb Rowan Collins <rowan.coll...@gmail.com>:
> 
> On 03/06/2016 11:16, Thomas Bley wrote:
>> why not try all types weakly from left to right in weak mode?
>> Rule: if type check would give a fatal error for a type, try next type.
> 
> This is what I suggested, but Bob is insistent that weak mode should always 
> select the same type as strict mode where there is a valid strict match, 
> which I guess makes sense.
> 
> A strict left-to-right check violates that:
> 
> function i(string | int $x) { echo gettype($x); }
> i(10); // string in weak mode, int in strict mode
> 
> function j(int | string $x) { echo gettype($x); }
> j('10'); // int in weak mode, string in strict mode
> 
> 
> The main complication that I haven't quite got my head round yet is the fact 
> that an int->float coercion is allowed in strict mode. So to be consistent, 
> weak mode needs to privilege that cast:
> 
> function k(string | float $x) { echo gettype($x); }
> k(10); // float
> 
> But in other cases it doesn't seem sensible to privilege float over string:
> 
> function l(string | float $x) { echo gettype($x); }
> l("1.5a"); // I would expect string, but float would succeed if attempted

Exact matches *ALWAYS* match without coercion.

Emphasis from the RFC:
Primarily, this issue is *avoided if a parameter type exactly matches the input 
type* or if PHP is in strict type mode. 

> Regards,
> -- 
> Rowan Collins
> [IMSoP]



Bob

Reply via email to