Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92346 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78975 invoked from network); 15 Apr 2016 17:28:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Apr 2016 17:28:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.21 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.21 mout.gmx.net Received: from [212.227.17.21] ([212.227.17.21:61362] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F9/78-29891-6B421175 for ; Fri, 15 Apr 2016 13:28:24 -0400 Received: from [192.168.2.102] ([84.187.18.28]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0MfBsk-1b7ANu281C-00Oq4Y; Fri, 15 Apr 2016 19:28:16 +0200 To: Larry Garfield , 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> <20.53.29891.17401175@pb1.pair.com> <57110BCD.5030009@garfieldtech.com> Message-ID: <571124C2.9040606@gmx.de> Date: Fri, 15 Apr 2016 19:28:34 +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: <57110BCD.5030009@garfieldtech.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:fmLSmsyEG1fxKR0eD8Y/L8AbRZlMLGJHnDm7GZmibhKw1Sj2C8c J/vZ45LPojjKV5pxg9xRMyj3a7fIbi7zPnHEkPjIadIer2N7B9WQSfAdMPloFaoAeQ5nEg0 8vK4ELKMp7zjDiCo0/aa/Yonda8ME6Dboql19YjRCgUOCJ9YE//PiHP8wkT2ED+97rQOScq mpjapO4zyTKicYNEckSyA== X-UI-Out-Filterresults: notjunk:1;V01:K0:CdA43BYfrKg=:PqRh23H7pRoZUebdUBnIGX 0m2QIKIgg5YR8+3j04c2ovRUB2itbN1730cyYgcl8I7psZXZcq0eSU4QqjPYtyyPCskFowe6q S5X/RrOhYrLDpuasLcPP7if1UCCc4GOmTlzX4BnNI1GxOpss5l60cXA+FJrpJCCiX2N5ysIVo e2armtPdn3btsg8H3xzpgvO33Q4WnSYYgteFvRRNx3adotmnq22ofDd0KOX8GnXy01TpSBogR HgYcT2Zikc0yQGPYNKotfHqMq6P2wyX4oTtpYy8AYHcoqHk039DlJ2AWp1NLFqGws3t5tyaDI fG5GbHHXjOy/LYNCe2f7j6/iYH9cG6+J9/1/cDNQwY0fl2H2BiyaKT6N82LubuXDNgwW7V5Yh 5tEZQkTfgVlgL59NTgLcSyMzqrzRpyTrqsnOc0ErITHngLoCMllcYqcK/kLa1/7kxNymPJtQ0 qILFSpc6oHOFHIS6CTSWqUnCboPJg2rKV5nxAPL9Vj64aFTrFiBkqXnlS+nC1nNNZu9G8hvRH 7BXiCiCxxeGp+FeXqXZzPY68bx/2Nw1ts0GvJRc0rRHvUqLdPqVKddqevY2YB8jn19JsvoatC Yhhr12hIPmagUlFtnp/X4aaPWhbmV/Q1scM2VMKsI8qKBhk1SyvImmGW1VdjQ9dlfoTIE8rum UWGt37+Oc3DD9Wn3OeGFsTwo4NdHa7TkGiTK8lg6iESba94YyP32QopZgegxv8LDc05Ivlbcs PknkCz330YVprdgzh5RYteZIJAr7GGQeroLXzSeGWPM0fyY6okYvnyaO8wXrb8PFB2luahcAm CfRCwmt Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: cmbecker69@gmx.de (Christoph Becker) On 15.04.2016 at 17:42, Larry Garfield wrote: > I think there's 2 general use cases for union types that would be "good > things", which are different for & and |, and have very little... > intersection. (*yaaaaaaa!*) > > The OR case is for cases where the language doesn't support a unified > case at all. The most obvious example here is array|Traversable. If I > want "a thing I can foreach()", then PHP right now has no way of saying > that syntactically. You have to type on array, or Traversable, or not > type at all. array|Traversable is what you really want, It is not what I would want, though. > because those > DO have an overlap (foreach-ablility), PHP is just incapable of > representing that otherwise. Maybe we should consider to accept an array as Traversable? Actually, I wonder why that's not already the case. > A similar example would be callable|SomeInterface. An interface can > specify a signature for __invoke(), which gives you documentation on the > format that is expected for a callable. However, you can't strictly > enforce that because then you don't allow for a function or closure that > fits the same method signature. That means you have to leave it > untyped. This, I argue, would be better *and* reasonably type safe: > > interface MiddlewareInterface { > function __invoke(RequestInterface $req, ResponseInterface $res); > } > > function middleware_builder(callable|MiddlewareInterface $m) { > // ... > } > > As that self-documents that MiddlewareInterface is the callable > signature we need, but still allows an arbitrary callable to be passed. > It's not perfect (I could pass a string of a function name that doesn't > have that interface and it would still explode), but it is an > improvement over middleware_builder() having no type specification at > all, as is the case today. In my opinion, `callable' is to weak a type hint to be really useful, and it would be better if we would improve that (generics come to mind). Then you wouldn't need MiddlewareInterface at all and be not afraid that somebody passes in an incompatible function. -- Christoph M. Becker