Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93742 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76050 invoked from network); 3 Jun 2016 11:59:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jun 2016 11:59:39 -0000 Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.102 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.102 blu004-omc2s27.hotmail.com Received: from [65.55.111.102] ([65.55.111.102:49177] helo=BLU004-OMC2S27.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/22-56709-B2171575 for ; Fri, 03 Jun 2016 07:59:39 -0400 Received: from BLU436-SMTP130 ([65.55.111.72]) by BLU004-OMC2S27.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Fri, 3 Jun 2016 04:59:37 -0700 X-TMN: [F/2E19nVJ+EvCBRCYmhM699JddNsca05] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_B245BD13-4420-41F0-A3A6-C4FD9D1801DD" MIME-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: <6d448fd8-8fda-d795-accb-6b96cd128ccd@gmail.com> Date: Fri, 3 Jun 2016 13:59:31 +0200 CC: internals@lists.php.net 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> To: Rowan Collins X-Mailer: Apple Mail (2.2070.6) X-OriginalArrivalTime: 03 Jun 2016 11:59:34.0548 (UTC) FILETIME=[6526F540:01D1BD8F] Subject: Re: [PHP-DEV] [RFC] [PRE-VOTE] Union types From: bobwei9@hotmail.com (Bob Weinand) --Apple-Mail=_B245BD13-4420-41F0-A3A6-C4FD9D1801DD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="us-ascii" > Am 3.6.2016 um 12:28 schrieb Rowan Collins : >=20 > 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. >=20 > 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. >=20 > A strict left-to-right check violates that: >=20 > function i(string | int $x) { echo gettype($x); } > i(10); // string in weak mode, int in strict mode >=20 > function j(int | string $x) { echo gettype($x); } > j('10'); // int in weak mode, string in strict mode >=20 >=20 > 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: >=20 > function k(string | float $x) { echo gettype($x); } > k(10); // float >=20 > But in other cases it doesn't seem sensible to privilege float over = string: >=20 > 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.=20 > Regards, > --=20 > Rowan Collins > [IMSoP] Bob= --Apple-Mail=_B245BD13-4420-41F0-A3A6-C4FD9D1801DD--