Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92313 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72653 invoked from network); 14 Apr 2016 19:32:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2016 19:32:21 -0000 Authentication-Results: pb1.pair.com header.from=j.boggiano@seld.be; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=j.boggiano@seld.be; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain seld.be designates 74.125.82.51 as permitted sender) X-PHP-List-Original-Sender: j.boggiano@seld.be X-Host-Fingerprint: 74.125.82.51 mail-wm0-f51.google.com Received: from [74.125.82.51] ([74.125.82.51:35435] helo=mail-wm0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/51-64966-340FF075 for ; Thu, 14 Apr 2016 15:32:20 -0400 Received: by mail-wm0-f51.google.com with SMTP id a140so2724513wma.0 for ; Thu, 14 Apr 2016 12:32:19 -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=xsEVKuhvQp6PEPMJa/y5Kmh2RXwdgVm/poRz+AFoLe8=; b=f7kkunmNKh1XRydt9rA1waDIC55BLstU7auKXyHfZcCKrj0a9fo64Tw6oSuS4pb3zH MdGKtYpxgiDsfMsUvNjRYhzOBBizk29J8IguWjj8pCxcnH+usC/E2ACJbhbUAwWEd9o3 dyVqxDwWgB2bNNUeNy3s/EOj+dcTCBDfqHb5a00btQI3jf1aH5+6R+23AteS7ZJ+YARd 5O+KPw2Bkjryc5AOkNLQczezwz/0i4rKoNcy0aD+vwiJ3rKkXbFbQSj+vA5M6I/PJVEb L1aYDeqcg1guSt7MYg3twR6LAaartu8wKZUVJIwEn7stY5YOC2nXDtCrGGI0U/n57etN MvQA== 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=xsEVKuhvQp6PEPMJa/y5Kmh2RXwdgVm/poRz+AFoLe8=; b=JnviTlJBl/CpYOZk5TfdwujFSw6LLZcFAPWivB28tM3DEesmypFfvBDe6vmmEaEsLL kCO8a9D2COE71Kwi8o8dUcAq+4izs+UNC9fknZva9U3dDCYQV0rz/sPocz6BkoM1zJ+C Q0ShU6tM8FreasCoWHCQ5IxUqL4o1pqOIkiFFFZWu89WshbeDYFM1hjHNsyIgBu5dpLY xPGGEvkq+SMGAQfIC/M8FxojnxPoqlTAU/057MiMaWmfXUlhdNGFUvE+o9WxZyIxwkFB heAb9a2xQJsYOw/03bV7ZcHwfPFP/TP8PDlCYqe4XbtldlkId5VndVkLms26BDG+txVK ZRhg== X-Gm-Message-State: AOPr4FVphWg+vzfBlVLaLAAHoBPrFjxqWYWi/9xXyoBmXIBi0hYBJwKrIh5tViTiuA6TaQ== X-Received: by 10.28.88.212 with SMTP id m203mr338671wmb.52.1460662337095; Thu, 14 Apr 2016 12:32:17 -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 c187sm8039405wme.16.2016.04.14.12.32.15 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Apr 2016 12:32:15 -0700 (PDT) To: 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> Message-ID: <570FF045.1040307@seld.be> Date: Thu, 14 Apr 2016 20:32:21 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <570FE8A9.4020809@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: j.boggiano@seld.be (Jordi Boggiano) Heya, On 14/04/2016 19:59, Stanislav Malyshev wrote: >> I don't know what is complicated about "string|Stringable" or "Foo|Bar" >> since it is super self-explanatory. However, I find myself checking the > > It may be self-explanatory for you. It's much less self-explanatory for > somebody just starting to learn. It is also very dangerous - if it's > either Foo or Bar, can you call Foo::stuff on it or not? If it's string > or not string, can you call strlen on it? Etc., etc. It adds a lot of > cognitive load and complicates the whole picture. 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). Please take that into consideration as well when arguing that it adds complexity. If it's rarely seen in the wild it's not very valuable but it's *also* not hindering newcomers often. > You may have a > specific use case where it is useful (which we have yet to see btw) but > please remember it's a language with literally millions of use cases and > users. 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. And it would save us one line of phpdoc as well because IDEs could infer the information from the code. Cheers -- Jordi Boggiano @seldaek - http://seld.be