Re: [RFC] Union Types

From: Date: Thu, 14 Apr 2016 09:12:17 +0000
Subject: Re: [RFC] Union Types
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-92284@lists.php.net to get a copy of this message
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

« previous php.internals (#92284) next »