Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101388 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47744 invoked from network); 19 Dec 2017 18:19:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Dec 2017 18:19:34 -0000 Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.87 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.87 mx106.easyname.com Received: from [77.244.243.87] ([77.244.243.87:56711] helo=mx206.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D0/E4-10479-338593A5 for ; Tue, 19 Dec 2017 13:19:33 -0500 Received: from cable-81-173-135-181.netcologne.de ([81.173.135.181] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1eRMU4-0008LK-Ow; Tue, 19 Dec 2017 18:19:22 +0000 Reply-To: internals@lists.php.net To: Andreas Hennings , Levi Morrison Cc: Michael Kliewe , PHP internals References: <3a8054fd-b99f-771f-1f6c-29cf198acdeb@phpgangsta.de> Message-ID: Date: Tue, 19 Dec 2017 19:19:20 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-DNSBL-BARRACUDACENTRAL: YES X-DNSBL-PBLSPAMHAUS: YES X-DNSBL-SPAMRATS: YES Subject: Re: [PHP-DEV] [RFC] Mixed Typehint From: php@fleshgrinder.com (Fleshgrinder) On 12/19/2017 6:43 PM, Andreas Hennings wrote: > The argument, which I support, is that "mixed" would allow to > distinguish against cases of "developer forgot to add a type hint" or > "no type hint due to legacy / BC reasons". > Also, with a "mixed" type hint, you know it is not "void" (this is > still the same argument). > The developer forgot the type constraint if there is no type constraint in: 1. the code 2. the DocBlock This is a simple rule that you can already adopt without any changes to the language. The thing is that mixed is not required at all at the moment PHP supports more sophisticated type constructs. As I said earlier, pursue them, not this. PS: It's interesting how people fail to see the power of union and intersection. This is currently happening on the Kotlin side too. A simple example for a union type was already given: `string|int`. Although in this case I would argue that anything that is convertible to a hash (e.g. `Hashable` as found in php-ds) and ensures an equivalence relation (not partial like float) should be usable as a key in an associative array. The introduction of dedicated types for this is definitely required in the language. That being said, union types are usually of interest if you are interacting with some library code that you cannot change (e.g. add interfaces to an existing type). Of course, one could argue that the introduction of dedicated interfaces in your own codebase plus adapters is the way to go but this requires much more effort than the in-place union declaration. Discriminating unions would be much nicer but that is something a proper enum impl should cover. Intersection is a whole other beast that is actually more powerful than the simple unions we know from PhpDoc. Consider the following example: interface Writer interface Reader interface Seekable interface AutoCloseable interface Closeable We could now continue and provide ReadableWriter, SeekableWriter, SeekableReadableWriter, ... but this already gets out of hand. An intersection on the other hand allows you to define exactly the features you require: fn f(Closeable & Seekable & Writer writer) This can of course be provided with a generics impl which would probably make the parsing impl simpler: fn f(T writer) -- Richard "Fleshgrinder" Fussenegger