Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101447 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29653 invoked from network); 29 Dec 2017 17:30:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Dec 2017 17:30:05 -0000 Authentication-Results: pb1.pair.com header.from=markus@fischer.name; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=markus@fischer.name; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fischer.name from 62.179.121.165 cause and error) X-PHP-List-Original-Sender: markus@fischer.name X-Host-Fingerprint: 62.179.121.165 vie01a-dmta-pe04-3.mx.upcmail.net Received: from [62.179.121.165] ([62.179.121.165:63011] helo=vie01a-dmta-pe04-3.mx.upcmail.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4B/5C-47595-B9B764A5 for ; Fri, 29 Dec 2017 12:30:03 -0500 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe04.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1eUyTo-0008TE-52 for internals@lists.php.net; Fri, 29 Dec 2017 18:30:00 +0100 Received: from mail02.home ([213.47.8.56]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id rtVy1w01b1CY7x901tVzq1; Fri, 29 Dec 2017 18:30:00 +0100 X-SourceIP: 213.47.8.56 Received: from mail02.home ([192.168.1.14] helo=[IPv6:::1]) by mail02.home with esmtp (Exim 4.72) (envelope-from ) id 1eUyTl-0005va-3z for internals@lists.php.net; Fri, 29 Dec 2017 18:29:58 +0100 To: internals@lists.php.net References: <72392123-d37b-26df-6886-218f48205f8a@fleshgrinder.com> <5171148a-3554-35a3-ab72-370e1aac4a3f@php.net> <6894aa94-0400-7a9a-f00c-47f1f556a4d0@php.net> Message-ID: <0b87f371-a6cf-e148-b4f1-855bc6ae880f@fischer.name> Date: Fri, 29 Dec 2017 18:29:56 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <6894aa94-0400-7a9a-f00c-47f1f556a4d0@php.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam_score: -2.9 X-Spam_score_int: -28 X-Spam_bar: -- X-Spam_report: Spam detection software, running on the system "scanner01.home", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi all, On 26.12.17 16:56, Sebastian Bergmann wrote: > Am 26.12.2017 um 16:46 schrieb lists@rhsoft.net: >> would you mind to explain this? > > "Foo|Bar", "array|string", etc. (still) make no sense to me. > > "scalar" makes sense to me although it is but an alias for > "bool|float|int|string". [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rhsoft.net] -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Scalar Pseudo-type From: markus@fischer.name (Markus Fischer) Hi all, On 26.12.17 16:56, Sebastian Bergmann wrote: > Am 26.12.2017 um 16:46 schrieb lists@rhsoft.net: >> would you mind to explain this? > > "Foo|Bar", "array|string", etc. (still) make no sense to me. > > "scalar" makes sense to me although it is but an alias for > "bool|float|int|string". I followed the discussion and found it interesting how strong the focus shifted about the discussion of the practical use cases. I would be for union types or scalars in ab instant, but I never had reason to scan our code-base and figure what would make really sense. Mind you this is a private codebase (Laravel based, as can be seen by some of the class names) but one where we tend to be very explicit about documenting everything, thus I knew I could just go ahead and extract the type hints using the '|' character and get back a pretty complete picture: $ grep -r '@param' *|grep \| | awk '{ print $4 }'|sort -u Attachment[]|Collection Attachment[]|null Builder|null Channel|Post|int|null Channel|int|null ClientInterface|null Client|int|null Collection|Attachment[] Collection|Channel[] Collection|Comment[] Collection|JsonapiModel[] Collection|Model[] Collection|Post[] DateTime|Carbon|string|null Dispatcher|null EloquentCollection|JsonapiModel[] Exception|null Group|Group[]|Client|Client[]|Channel|Channel[]|null Group|int|null JsonapiModel|null Model|int|null Post[]|null Post|int|null Profile|int|null ResponseInterface|null Throwable|null User|int|null \ArrayAccess|array|JsonapiModel[]|null array|false array|null int[]|int int|int[] int|null mixed|null null|LoggerInterface null|Model null|Model[]|Collection null|string string[]|Expression[] string|int string|null This is extracted from a codebase with ~400 files and ~43k LOC (incl. comments). I'm not saying anything like this is relevant codebase, but it's a project whose code quality I know well and I know the reason for every piece there. Since the discussion focuses on scalars here and ignoring all the nullables (they're auto-documented that way via PhpStorm) as well as ignoring the pseudo array-type hints, this leaves us really with only: - array|false Only 1 occurrence, used for crafting a remote HTTP call which has an interface which accepts either an array or false ?‍♀️ - string|int Only 1 occurrence, used for error codes which may come in either flavor, send back via HTTP somewhere I was surprised how less of a use we would really have for a) `scalar` itself and b) scalar unions. OTOH, typed array hints seem to be very useful as are class based union types. Although if one looks closely, it's clear this isn't a "union" problem, but rather an emulation due to the absence of Generics, e.g. Attachment[]|Collection Is clearly a replacement for something like Collection I hope I didn't distract to much from the discussion but though I throw in some data from an actual application. I'm sure there are much better OSS projects out there which could be used for such analysis. thanks, - Markus