On Wed, 13 Apr 2016, Levi Morrison wrote:

> As alluded to in an earlier email today[1] I am now moving the Union
> Types RFC[2] to the discussion phase. The short summary of the RFC is
> that it permits a type declaration to be one of several enumerated
> types. For example, this is a potential signature for a multi-type map
> routine:
> 
>     function map(callable $f, Array | Traversable $iterable);

I think what I am missing in the RFC is behaviour with scalar (weak) 
typehints, and which type the variable in a class would be converted to. 
Take for example:

function foo(int|bool $var) { echo get_type( $var ), "\n"; }

foo(5);     I guess int(5)
foo(false); I guess bool(false)
foo(0.5);   It could be either int(1) or bool(true)

And what if the hint would be "bool|int" ?

Although it's probably easy enough to solve in this case, the RFC should 
detail how type conversion works with the scalar types.

cheers,
Derick

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to