Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106848 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86329 invoked from network); 4 Sep 2019 13:46:44 -0000 Received: from unknown (HELO mail-qt1-f172.google.com) (209.85.160.172) by pb1.pair.com with SMTP; 4 Sep 2019 13:46:44 -0000 Received: by mail-qt1-f172.google.com with SMTP id g4so23879816qtq.7 for ; Wed, 04 Sep 2019 04:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=N+5eUAw+6LGvUorC14jDRWXMY7AcIlEXX5ScnRTvLIM=; b=pWiXQ1R42rZjPczPUoyC15P24KgoIfXGWk9G/m8o70g/s3rgkXWTB2XRJfaG7I5b4L 8zQDaXXfNbvT3iX0Mog06AfsVtL1WhcSLILLRjL3Aey6hsNZ3pWzhbi5PnlhM6Ja3/T6 P7D/aN9GIkwQUfF/6t+Y59uS2ljlCcEgZNFdC3AQjU7m4Lhzqek6I5nvYmF/7TtQ+8d/ IPK7shOW5oeuZEZ2x8E+tgJZMvso03S9NG/pP8/1j2ygf5WLh9eRp1w2b6WwOV0sipe3 IwcU/sFxeyn+/h62pYz5mjACaOvjpAHQOGh+fPMkeC8oe3ytlpkLzN74x63blBPuNosy 48uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=N+5eUAw+6LGvUorC14jDRWXMY7AcIlEXX5ScnRTvLIM=; b=XbxakWJnwS0zZBo3jc+4fTzXVQNbGzZ+Wq556Hgu2Fx4u308mx5HklfRJgRu/J3JG5 UM8iSPjz/t2Kjoxr9Ji03IPCBUqlFr9olQaZyfAAzlfpplh9p9IZs59i/1Y1uD8WuutA dE76ZY2AYx48PDYhvFisDa1dDm27f5k3zdyiaZieG3GXrfPrgg14DYdbkilbtOTS7dXg wbAvrlbFMgFjxIAAxzyxoKM8lBVCAF7D0/GtCoOhgCM9B2z3rckyeC3oKuiyQzQbGJEj Ff9iZaxvpq1zq8h9966V2Injx8NDdQ0GUPx/Sq9jxCGDnoH3RCsT6qm/PzG38MVVJ4cG Msrg== X-Gm-Message-State: APjAAAVIXEncXggoS7HrB5yRabSUEZjlR14XPDf85eDEHqc5cWlYH6ig QFtUBGss2CIY9R0+OOsIbbc= X-Google-Smtp-Source: APXvYqwsX/7C2Gf2LJXikIl06FiDGY+2Kyhx86DSqHq81IwONiDW2Z6tAobLAeVi8+ykCf5CJlcTag== X-Received: by 2002:ac8:905:: with SMTP id t5mr28115375qth.109.1567596037057; Wed, 04 Sep 2019 04:20:37 -0700 (PDT) Received: from [192.168.0.105] (pool-98-113-211-93.nycmny.fios.verizon.net. [98.113.211.93]) by smtp.gmail.com with ESMTPSA id 10sm1069802qtd.90.2019.09.04.04.20.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Sep 2019 04:20:36 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) X-Mailer: iPhone Mail (16G77) In-Reply-To: Date: Wed, 4 Sep 2019 07:20:35 -0400 Cc: Nikita Popov , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Nicolas Grekas Subject: Re: [PHP-DEV] [RFC] Union Types v2 From: matthewmatthew@gmail.com (Matthew Brown) - Agree on the usefulness of a stringable meta-type. - Hack supports an explicit =E2=80=9C: this=E2=80=9D return type (without do= llar) when returning =E2=80=9Cnew static(...)=E2=80=9D. I think I might pref= er that to =E2=80=9C: static=E2=80=9D. - =46rom a type perspective, I don=E2=80=99t understand the =E2=80=9Cint|voi= d=E2=80=9D idea - it might make your users=E2=80=99 life easier, but doesn=E2= =80=99t accord with how PHP works (which treats void as null to consumers). - if we=E2=80=99re adding to some future wish list, would love to have suppo= rt for =E2=80=9C: noreturn=E2=80=9D when a function always throws or exits On Sep 4, 2019, at 5:58 AM, Nicolas Grekas wr= ote: >>=20 >> https://github.com/nikic/php-rfcs/blob/union-types/rfcs/0000-union-types-= v2.md >=20 >=20 > Thank you Nikita, this would be a hugely welcomed step forward! Can't wait= > to get rid of all those docblock annotations! >=20 > I've some additional suggestions that would greatly help remove more > docblocks and provide engine-enforced type-safety, maybe for the "future > scope" section. We use the all in Symfony: >=20 > - we miss a stringable union type, for `string|__toString`. This is > required when an API need lazyness regarding the generation of some > strings. Right now, we have no other option but using string|object. > - we use "@return $this" quite often. On the implementation side, I'd > suggest enforcing this at compile time only (enforce all return points a= re > explicit, and written as "return $this", similarly to what is done for > nullable/void return types.) This makes sense only for return types. > - we use "@return static" quite often too, typically when a method > returns a clone of the current instance. If anyone wonders, this is not t= he > same as "@return self" of methods overridden in child classes. This make= s > sense only for return types. >=20 > About union types with void in them, we do use one in Symfony: > Command::execute() has "@return int|void". The reason is that if we were t= o > use "?int" instead, the engine would force the community to add "return > null;" where no return statement is needed at all most of the time. Right > now, we consider that the transition cost for the community is not worth > the extra boilerplate this requires. Note that there would be only one > friendly path forward: trigger a deprecation when null is returned, asking= > ppl to add "return 0;". Not sure how this should impact the proposal, but= > I thought it could be worth sharing. >=20 > Thanks again, > Nicolas