Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92284 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4800 invoked from network); 14 Apr 2016 09:12:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2016 09:12:20 -0000 Authentication-Results: pb1.pair.com header.from=derick@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=derick@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 82.113.146.227 as permitted sender) X-PHP-List-Original-Sender: derick@php.net X-Host-Fingerprint: 82.113.146.227 xdebug.org Received: from [82.113.146.227] ([82.113.146.227:37742] helo=xdebug.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AB/C4-12455-4FE5F075 for ; Thu, 14 Apr 2016 05:12:20 -0400 Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 8D5E1DEFB4; Thu, 14 Apr 2016 10:12:17 +0100 (BST) Date: Thu, 14 Apr 2016 10:12:17 +0100 (BST) X-X-Sender: derick@whisky.home.derickrethans.nl To: Levi Morrison cc: internals In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Subject: Re: [PHP-DEV] [RFC] Union Types From: derick@php.net (Derick Rethans) 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