Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93753 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2038 invoked from network); 3 Jun 2016 15:16:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jun 2016 15:16:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=j.boggiano@seld.be; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=j.boggiano@seld.be; sender-id=pass Received-SPF: pass (pb1.pair.com: domain seld.be designates 74.125.82.46 as permitted sender) X-PHP-List-Original-Sender: j.boggiano@seld.be X-Host-Fingerprint: 74.125.82.46 mail-wm0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:35905] helo=mail-wm0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/92-22497-54F91575 for ; Fri, 03 Jun 2016 11:16:23 -0400 Received: by mail-wm0-f46.google.com with SMTP id n184so738389wmn.1 for ; Fri, 03 Jun 2016 08:16:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seld-be.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=KSZBalDFCkWWjG8cw9262I2wsQrszt//Gl642z+Uaec=; b=1EsQlvDzC2DRyZLWLbM+LyAx/FZu9EoMnk/Qn+SSzEZtrWkekmS1QoC++SSbv1oZ/Y rvYH02s0i0s8/7GDIUuohN2eQ/rUiDx7eGs0wMuWF4m7UCxBtjZRuufthSeTYVAYLoSc 5AT4x+2MgjRHu+wf7C/TqBZGyhvSzB/xfOqkMYdJdSOVXrLaKKurYxw/6ZWbqslZBsE5 nCU8KSV/YF9PhEzt196CHhmWRaY7S5D8fD+JaDwd+OnQxBdIzxPzo1sQkwtiRQDTw+bz Xy7wo48+cRDyr3SISUMUuF+CVmfXO/GjleRuuPAg9/tna93A6ks6bXrgTA1eFJJYaxX0 pcog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=KSZBalDFCkWWjG8cw9262I2wsQrszt//Gl642z+Uaec=; b=VZpAY25AWpMI6zRknOTMN6IWIyI0LeqTy9IPPeYIZk/aSXiMm63yVvhy7lhWpZaFgR Fsz2p/FgxGI98vvURELolD+ktbi3T9UWGwO8d//k6yJfPOkkP06/0UTLL56+g4dulRMb illD8xkZnEBWs22PlVds/0rhpyP90/hoerxSBjq3GxE06I+2+cQ7uTmlQraLGArAEtn+ wSzyKDDUshbSmk5r9Pf9SzRwAxMlA9Hbj8PrYc1RqCGb6tC9rIQ3HBsTTpWG9XB7bgnV sU+oPKMyUu6DT0iy07S/52G2ly7LqrA4Sty3D9I2VJ8viDrRh6RqAxdlEPWcKPH1BHIh uhQw== X-Gm-Message-State: ALyK8tJf00Y7/8MPnQAadg6Qim4u85j/0CxigrUDG2OjbtDvDT+KLM0xw5non0wp9H7qyA== X-Received: by 10.28.102.196 with SMTP id a187mr7468wmc.99.1464966979229; Fri, 03 Jun 2016 08:16:19 -0700 (PDT) Received: from [192.168.0.2] (cpc74585-lewi13-2-0-cust978.2-4.cable.virginm.net. [82.25.75.211]) by smtp.googlemail.com with ESMTPSA id q194sm21592wme.18.2016.06.03.08.16.16 for (version=TLSv1/SSLv3 cipher=OTHER); Fri, 03 Jun 2016 08:16:16 -0700 (PDT) To: 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> <652fdc5a-a164-2054-ed61-305a2b72330a@gmail.com> <20160603142421.346B81A81725@dd1730.kasserver.com> <9814df22-9854-616b-bf02-d0742efefaff@gmail.com> <20160603145857.8413F1A8323C@dd1730.kasserver.com> Message-ID: <1fb072b3-9b9e-1dfd-6b39-7875587b6c7d@seld.be> Date: Fri, 3 Jun 2016 16:16:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <20160603145857.8413F1A8323C@dd1730.kasserver.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] [PRE-VOTE] Union types From: j.boggiano@seld.be (Jordi Boggiano) On 03/06/2016 15:58, Thomas Bley wrote: > 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. That is a useful case, and don't forget also return values, e.g. all the XX|false-kind of return types it's also nice to have. I don't think for function arguments it's massively useful and I doubt it'll get put everywhere, but it's nice to be able to express this when you have to. Cheers -- Jordi Boggiano @seldaek - http://seld.be