Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93801 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62528 invoked from network); 5 Jun 2016 08:15:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jun 2016 08:15:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain thomasbley.de from 85.13.128.151 cause and error) X-PHP-List-Original-Sender: mails@thomasbley.de X-Host-Fingerprint: 85.13.128.151 dd1730.kasserver.com Received: from [85.13.128.151] ([85.13.128.151:60089] helo=dd1730.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/51-55579-99FD3575 for ; Sun, 05 Jun 2016 04:15:21 -0400 Received: from dd1730.kasserver.com (dd0802.kasserver.com [85.13.143.1]) by dd1730.kasserver.com (Postfix) with ESMTPSA id 7D4B81A80165; Sun, 5 Jun 2016 10:15:18 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SenderIP: 95.91.246.42 User-Agent: ALL-INKL Webmail 2.11 In-Reply-To: References: <0A.C5.62101.1C860575@pb1.pair.com> <68b821ac-d71f-4be5-8dca-ae94db332630@gmail.com> <20160603101659.D466A1A81FC5@dd1730.kasserver.com> <6d448fd8-8fda-d795-accb-6b96cd128ccd@gmail.com> <652fdc5a-a164-2054-ed61-305a2b72330a@gmail.com> To: rowan.collins@gmail.com, bobwei9@hotmail.com Cc: internals@lists.php.net Message-ID: <20160605081518.7D4B81A80165@dd1730.kasserver.com> Date: Sun, 5 Jun 2016 10:15:18 +0200 (CEST) Subject: Re: [PHP-DEV] [RFC] [PRE-VOTE] Union types From: mails@thomasbley.de ("Thomas Bley") maybe you can add a few examples to the type table in the rfc, so everybody knows how it actually works: function test(int | float | string $a) {var_dump($a);} test(42.0); // float(42) test('42'); // string(2) "42" function test2(int $a) {var_dump($a);} test2(42.0); // int(42) test2('42'); // int(42) function test3(int|bool $a) {var_dump($a);} test3('foo'); // true Regards Thomas Bob Weinand wrote on 03.06.2016 14:30: > >> Am 3.6.2016 um 14:18 schrieb Rowan Collins : >> >> On 03/06/2016 12:59, Bob Weinand wrote: >>>> 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. >> >> Gah, I keep making that mistake in my examples. I did say I was struggling to >> get my head around things! ;) >> >> I'm still missing an explanation of exactly where you derived the current >> proposed rules from, though. The RFC just states "these rules are not an >> invention of this proposal", but goes on to say "applies PHP casting rules in >> a sane way", which implies some decisions were involved in drawing up these >> rules. >> >> I think you may be right that the rules are as simple as they can be, and I >> don't want to waste too much of your time, but a basic summary of the >> reasoning used would be much appreciated. >> >> Regards, >> -- >> Rowan Collins >> [IMSoP] > > The *weak casting* rules (i.e. what gets converted how and what can be > converted to the other type) are not an invention of the proposal. > > The proposal however defines the specific order. > > I’ve added a reasoning why not left-to-right now. As this seemed to be asked > multiple times. > > Also, the specific reasoning why I propose that specific order the rules are > in: >> Otherwise PHP's casting rules are applied in an order to be as lossless as >> possible. > > That’s really the only motivation behind that. > > Bob > > > > >