Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106847 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72406 invoked from network); 4 Sep 2019 12:25:13 -0000 Received: from unknown (HELO mail-ot1-f47.google.com) (209.85.210.47) by pb1.pair.com with SMTP; 4 Sep 2019 12:25:13 -0000 Received: by mail-ot1-f47.google.com with SMTP id z17so19948512otk.13 for ; Wed, 04 Sep 2019 02:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TjQshjIjqLsQJriMt3oviAb8ZyPem3POYtvBzTqEjKE=; b=UMhYXNOPQ8tsnmAU6E8ckBnA/GlB7Mo1ZF7ZjZgHx9KMtx/f+RofjCKXqoCZC2RhBd STTETs2DJ34bdhb4ImuCqQtx31W4gRJUoxlzWh5pdAC1knT0Z1em4T7ln6ZNTzXmIfjJ F+uABYSAtuR/sAGgHPtXtBSjdNeS5coB2SEfghIeixR8iu+ohdMGL0RDKPw8XlwvK+PY rt/WZUrzEoSD0DfJDfp/4g1LQDqgjYi7khpwDvrVyiQ4ylNBHD8XZiUkhsLFNrfNHL5s UGau9EB8OzEnkP8GxbL7LoGXKJLH82/cJEacWPhqwjgw9VMUvaX40qSzvaCtC0i3MSUQ UWiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TjQshjIjqLsQJriMt3oviAb8ZyPem3POYtvBzTqEjKE=; b=qGTnBJ9MMCeLHuhnkBWnXF+SUIRViMgidBandt3LHEe2yjBAPlsSLGCFAOiWi1/+QT GXDlEGsAkzDHfMdUr2jd2+L7GC4Wp60UnD1x8UQJXPVNgjQ5CkjdJRY85MwO4emDI0gp ESeLhAuKP0IHTZnHJe2bphDKrxqCJcockW+hPfY/aPzoHuDHHlGfxI2s3QgGgPCT/tR3 Ep7j7V8ojN3yz5QzTMUDrTOiYRcWJmwXlhZjhOQ3Pt3X1GsmZT8iwciqAO0yHfgmLNSe rGy8+o237CfpRnolg7+HSvZPtQObTWe8kxR79g+CbhD6PjfTy4VPSnXBPjqlM3Zs1749 aJMA== X-Gm-Message-State: APjAAAW3YaiLyjFrZRoAw6e3NOuTQAg89Ta5QcucWc4Xn/d4TWUF+/JG BEAoIVqTbP+Ud+3Vfkwf2P4ru/07eX7AfVQ+d+4= X-Google-Smtp-Source: APXvYqx5IacsGxf0gheUyi7F6eGK5swmD6ClxJXcjgiJJXGqS6Z+f5bjHYVi92rKuEQFJehNjt9g9TKuFQ2nMo1LClk= X-Received: by 2002:a9d:744c:: with SMTP id p12mr863476otk.198.1567591144999; Wed, 04 Sep 2019 02:59:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 4 Sep 2019 11:58:53 +0200 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000059d08e0591b741d4" Subject: Re: [PHP-DEV] [RFC] Union Types v2 From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --00000000000059d08e0591b741d4 Content-Type: text/plain; charset="UTF-8" > > https://github.com/nikic/php-rfcs/blob/union-types/rfcs/0000-union-types-v2.md Thank you Nikita, this would be a hugely welcomed step forward! Can't wait to get rid of all those docblock annotations! 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: - 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 are 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 the same as "@return self" of methods overridden in child classes. This makes sense only for return types. 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 to 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. Thanks again, Nicolas --00000000000059d08e0591b741d4--