Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93751 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97568 invoked from network); 3 Jun 2016 14:59:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jun 2016 14:59:00 -0000 Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; 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:43884] helo=dd1730.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 86/B1-22497-43B91575 for ; Fri, 03 Jun 2016 10:59:00 -0400 Received: from dd1730.kasserver.com (dd0800.kasserver.com [85.13.143.204]) by dd1730.kasserver.com (Postfix) with ESMTPSA id 8413F1A8323C; Fri, 3 Jun 2016 16:58:57 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-SenderIP: 88.67.42.43 User-Agent: ALL-INKL Webmail 2.11 In-Reply-To: <9814df22-9854-616b-bf02-d0742efefaff@gmail.com> 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> <20160603142421.346B81A81725@dd1730.kasserver.com><9814df22-9854-616b-bf02-d0742efefaff@gmail.com> To: internals@lists.php.net, rowan.collins@gmail.com Message-ID: <20160603145857.8413F1A8323C@dd1730.kasserver.com> Date: Fri, 3 Jun 2016 16:58:57 +0200 (CEST) Subject: Re: [PHP-DEV] [RFC] [PRE-VOTE] Union types From: mails@thomasbley.de ("Thomas Bley") To me type declarations help to make my code easier and more consistent. Having multiple scalar types for a single function parameter is against this goal since I need extra logic to handle this. e.g. function foo(string | int | bool $bar) {} makes no sense in weak mode since string can already handle int, bool, float, etc. having different behavior between foo("42"); function foo(string $b) {echo gettype($b);} // string and foo("42"); function foo(string | int $b) {echo gettype($b);} // integer also makes no sense to me. Things like string|array are useful (e.g. str_replace) since we can cast the string easily to array and calling a string parameter with an array would give a fatal error. Regards Thomas Rowan Collins wrote on 03.06.2016 16:32: > On 03/06/2016 15:24, Thomas Bley wrote: >> maybe easier to get a majority from voters if defining union types only in >> strict mode for 7.1? > > No go, I'm afraid. > > Strict types are opt-in at the point of calling the function, but union > types are a feature of the declaration. If I write "function foo(int | > string $a) {}", it is not up to me whether it's executed in strict mode > or not. > > We'd have to throw an error of "function %s cannot be called without > strict types enabled", and that goes against the entire premise of > strict types as implemented. > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >