Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92341 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71062 invoked from network); 15 Apr 2016 16:56:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Apr 2016 16:56:56 -0000 Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.15 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.15 mout.gmx.net Received: from [212.227.15.15] ([212.227.15.15:64844] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 66/C6-29891-75D11175 for ; Fri, 15 Apr 2016 12:56:55 -0400 Received: from [192.168.2.102] ([84.187.18.28]) by mail.gmx.com (mrgmx003) with ESMTPSA (Nemesis) id 0MhRUQ-1b4unp1wh8-00McgB; Fri, 15 Apr 2016 18:56:51 +0200 To: Jordi Boggiano , internals@lists.php.net References: <570E99AC.3090804@fleshgrinder.com> <570EA5EB.8090501@fleshgrinder.com> <570EAB0D.6080706@gmail.com> <570EB67E.8010908@garfieldtech.com> <5B147E88-CC0A-4CBC-A49D-C7FE3BF557C0@zend.com> <6F.C3.12455.94C5F075@pb1.pair.com> <20160414094440.GF19347@phcomp.co.uk> <570FD94F.90703@fleshgrinder.com> <570FE8A9.4020809@gmail.com> <570FF045.1040307@seld.be> Message-ID: <57111D65.10802@gmx.de> Date: Fri, 15 Apr 2016 18:57:09 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <570FF045.1040307@seld.be> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-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LV4nBmRp13bCcre7L0y6snSM7UuMhjf/ dQCtsYo Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: cmbecker69@gmx.de (Christoph Becker) On 14.04.2016 at 21:32, Jordi Boggiano wrote: > I don't really think it's much more complex to grasp `Foo|Bar $foo` than > only `Foo $foo`. I mean once you grasp the concept of type hints you > probably have by then a good understanding of || and hopefully can > derive understanding from there. > > That said I agree it's rarely useful, and as such I am not expecting > we'll see this all over the place, it's just nice to have when you need > it, but I can't think of very many valid cases (nullable types are much > more common). There may not be very many cases for union types, but that might not hinder some programmers to make extensive use of the feature, which others may encounter in their APIs. > Just to highlight one use case I can think of, here is one: > > https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/MongoDBHandler.php#L51-L53 > > We need some sort of Mongo thing, and there are two available with > different interfaces, so here both are accepted but as you see in the > code below they are handled kinda separately. It would just save us > those 3 lines of check if we could type-hint appropriately. It occurs to me that this is an instance of parameter overloading: accept one of two (or more) unrelated types and handle them separately in a single function. An alternative would be to have two (or more) (factory) functions, each accepting one of the alternative types (perhaps delegating to a common function for the common code, if necessary). -- Christoph M. Becker