Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101423 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26017 invoked from network); 26 Dec 2017 16:21:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Dec 2017 16:21:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=lisachenko.it@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=lisachenko.it@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.182 as permitted sender) X-PHP-List-Original-Sender: lisachenko.it@gmail.com X-Host-Fingerprint: 209.85.128.182 mail-wr0-f182.google.com Received: from [209.85.128.182] ([209.85.128.182:42617] helo=mail-wr0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 60/D4-58518-217724A5 for ; Tue, 26 Dec 2017 11:21:39 -0500 Received: by mail-wr0-f182.google.com with SMTP id w107so9061321wrb.9 for ; Tue, 26 Dec 2017 08:21:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=xql7/v9WkOct47kFdUP7ZZaot8RZWgzcPlBFCFbWjS8=; b=Sux6R95waD+++hVPihruaMzfA7KEEUickPWmTVeuRuodq4BgRnSYxlHY00cA6ngxbX 270K0IolBBiIwAf6IrZ9zEQ6gH/Pq0ZGZ/3vwUNOVquHBx8Ijm3D/qTtcEYm0JuhXXXF Yvl4RTLLsKJ19vyx2DYOQML82joBPu/UVNDmbW3HTsKy6BIsPFJv59yaR+r3YE+wFDgC k5S/ElB6AfgpbucM36PvW0ZSMG/3kE+zZd8kafM64FmqetKTVQK0q+lswEFOMdnataZU V6YdH7yQgkb6MUZ5si3Z7ljO3Fk0mZkAfEByiMckmDa0Z+ZErln+VJ8IlXr3BczAZvVh laKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=xql7/v9WkOct47kFdUP7ZZaot8RZWgzcPlBFCFbWjS8=; b=ges8uIljtDE0jHjhLq1cK0bv9c3nvt2304cQ+J7QPugxqCAz61Kp2l1TxceqtRUXYj lzlQApHu+Cws+hayyKaAK7+3gOzda5R0qVCmK2Sx+S1SnVO1wQtqHREXFShd09s6cNdu Dd3JoUwLS2WCltS9KVCywMpFSRrGc+y3dG4W2ypJ0Oco8iI7VpUu5mU3fo/FGjLzMEbj 8TtrqVujTv0wUbOJj2B7ZVSz041yfnQ9fmo9u4mmX/Nle3y/8wTi3NcSdIPLuJRn9Otl 6AKNYCs0U4l0U/EBvjL0WPiBJgXfj5qkCPdoE9aNsx29c9xv71ULIX3bI1IrViyK1jdh 7dTA== X-Gm-Message-State: AKGB3mLkeaRnxdSmDABclh2l0y81lUdnlRZWSaMV5fFbD1hgPm0U8zBs GvD0rZeAd3ju8GPxSN8aIVaEDiNvK6UCHH3zKF/VW8FJ X-Google-Smtp-Source: ACJfBos6fugyeO049AOCSz0bOqAdWF1IlPNt774TiV3ffFC1xEDLGOCCUv93D9N+lak69+rSlZifIv85Ba8pXIeqxm4= X-Received: by 10.223.163.135 with SMTP id l7mr27732258wrb.2.1514305296197; Tue, 26 Dec 2017 08:21:36 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.141.174 with HTTP; Tue, 26 Dec 2017 08:20:55 -0800 (PST) In-Reply-To: <88921EA7-EB68-4630-AA9E-DE0C04342F0B@heigl.org> References: <72392123-d37b-26df-6886-218f48205f8a@fleshgrinder.com> <5171148a-3554-35a3-ab72-370e1aac4a3f@php.net> <88921EA7-EB68-4630-AA9E-DE0C04342F0B@heigl.org> Date: Tue, 26 Dec 2017 19:20:55 +0300 Message-ID: To: Andreas Heigl Cc: PHP internals list Content-Type: multipart/alternative; boundary="f403045f1466431a1a056140adec" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Scalar Pseudo-type From: lisachenko.it@gmail.com (Alexander Lisachenko) --f403045f1466431a1a056140adec Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable In some distant future it could be implemented in more natural way with classes for primitive types and automatic boxing/unboxing for primitive built-in types: Php\Type\Object Php\Type\Scalar =E2=8C=8A Php\Type\String =E2=8C=8A Php\Type\Integer =E2=8C=8A Php\Type\Float =E2=8C=8A Php\Type\Boolean Php\Type\Array And it will be easy to typehint all scalars via common parent class: public function acceptsScalar(Scalar $scalarValue). But all scalar objects in this case should be implemented as immutable or should be passed as copy (like arrays). So, I would vote no for adding special scalar typehint without mapping it to the common class or interface, like iterable =3D> Traversable, callable =3D> Closure, etc Best regards, Alexander 2017-12-26 18:59 GMT+03:00 Andreas Heigl : > Hey All. > > > Am 26.12.2017 um 14:38 schrieb Sebastian Bergmann : > > > >> Am 24.12.2017 um 15:34 schrieb Fleshgrinder: > >> I prepared a PR to add the `scalar` pseudo-type to PHP after the > >> discussions around adding a `mixed` pseudo-type. I strongly believe th= at > >> it makes sense to provide the most common primitive union types with > >> handy aliases even if we are going to add union types in the future to > PHP. > > > > Thank you, Richard, for working on this. > > > > I spent a lot of time this year introducing scalar type declarations in= to > > existing code bases. In quite a few cases I was not able to do so becau= se > > the existing code works with parameters that can be of two or more scal= ar > > types. With PHP 7.2, I can only document this outside of the code using > > @param annotations (until the code has been refactored to work with onl= y > > one parameter type). > > > > With a "scalar" type declaration I would not have to fall back to @para= m > > annotations and could express the type in actual syntax. > > Just a stupid question from someone that isn't following all the > discussions here. So forgive me if the question was already asked and > answered. > > What would be wrong with a "composed type hint"? Something like > int|float|double $numeric. Or array|Traversable $iterator? > > It would allow people to add "mixed" typehints without having to introduc= e > multiple typehints that combine different scalar typehints. And it could > even allow typehinting different Objects in one function. > > Yes, it allows people to shoot themselfes into their own feet. > > And I'd only allow that for parameter types and never ever for return > types. > > But it might be an idea. > > Cheers > > Andreas > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f403045f1466431a1a056140adec--