Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112785 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43156 invoked from network); 6 Jan 2021 17:18:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2021 17:18:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DC4541804DD for ; Wed, 6 Jan 2021 08:55:07 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 6 Jan 2021 08:55:07 -0800 (PST) Received: by mail-ed1-f45.google.com with SMTP id i24so4979371edj.8 for ; Wed, 06 Jan 2021 08:55:07 -0800 (PST) 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=jZVTOoRf+ufcsY0yR7T7MgBjoFhy987zVj+Zcdo/YGQ=; b=D8sGyfjE5iwHdiUcALwoqo7EBYQ8zyh4WgNgnsF1pTFOSij08mOS3tYcphMoMqAml0 BwpbN6fp2wD4u6M4zffPiteVCuqmng7ZqxEcUg0CJXHdwxIvqYSDIZsHvSbAg0oODbAH ojUwQjmJaQf+xtVjabAax0Wc0/ReaGexau2Ht22yy24/mkNTH+Ppw2BW3hJEs/o/ksTk 2u4xb2Sqnzji1Rc/SwNg0NNDwFCRFjg3zCl5InLItuOcZ9lwOXIovsEwE8Gfbpooj0OL oLHrZG3K9PqeGClwnOo8sITOF7yJmnlctPVFA9vfjFLOQXoJvoFS675A0OIHs7OtG94U /CXg== 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=jZVTOoRf+ufcsY0yR7T7MgBjoFhy987zVj+Zcdo/YGQ=; b=E+HtuYq9RP7w1tsO8Ozl6IBojIu75bIea/of5poJZme3hMpved++5InrzOaf+zZoMz Fc44ijDsSubFmCbFayVZMSafCoSPhJWHCcCwaM7/MynRrrXdL86UMiP77CkAgEOpUbMF ZCKzDQvxAh8cIWJUBTGoeAlB6evH9kQZAj1V5GqixkP3u0AEZG8ggjUeInjAvB/3vXmR bMr+DxHejr5chmEXulpiWm/cKD8HYmNRLBopU1Jg0Z4O3DT5ZhKKT1jpkMMdZTyPoF1S 7X9ES+JXb3PpiTR2sfNWwlZng8KwOcyZnELPuilOraGOS/af+Z9RPUsW/085DKhFg9Lh 08Nw== X-Gm-Message-State: AOAM531VPRAiUqyAO9ZLWj7aLEMujdj1BsVlZn1oJjXPPDI6jTQo0pzC HO7SjSz5818cr7Z/l+lZu5ub9Y9DXGHaIGuufMFvgPPmNBbK9Q== X-Google-Smtp-Source: ABdhPJzre8MvHwoCX7qv1Ofb34TWNaswfGo8io6bFP0xFMQuyOuwpwh3N+guY3YXfieSrqrI2U5tfxjt7o5UK9JvZ+4= X-Received: by 2002:a50:d5c1:: with SMTP id g1mr4738966edj.299.1609952105156; Wed, 06 Jan 2021 08:55:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 6 Jan 2021 17:54:53 +0100 Message-ID: To: Nikita Popov Cc: =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= , PHP Internals List Content-Type: multipart/alternative; boundary="0000000000005555ff05b83e2fb3" Subject: Re: [PHP-DEV] [RFC] Adding return types to internal methods (PHP 8) From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --0000000000005555ff05b83e2fb3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 28, 2020 at 7:54 PM M=C3=A1t=C3=A9 Kocsis wrote: > > > Hi Internals, > > > > Last year, Nikita started a discussion about adding return types > > to non-final internal methods: https://externals.io/message/106539 . > > > > I'd like to restart the conversation, since I've just created an > > implementation > > for the first step of the migration: > > https://github.com/php/php-src/pull/6548 > > (I had to start a new email thread because I don't have the original > one). > > > > My implementation currently emits a deprecation notice during inheritan= ce > > validation > > for each method which omits the return type of its parent. This means > > that the parent return type is not yet enforced when the child omits it= , > > neither during > > inheritance, nor at run-time. However, as soon as the child class > declares > > return types, > > everything will behave as usual, so variance and run-time return value > > checks > > both apply. Finally, in a couple of years, PHP 9.0 could make the > > declaration of > > return types required. > > > > If there are concerns about methods which are already declared with the > > wrong return > > type, we could lax the restrictions even further, and only emit a > > deprecation notice > > instead of a fatal error in this case as well. > > > > I chose the above approach over inheriting the return type implicitly > > (which was suggested > > by Sara) because I believe it has a few advantages: > > - It causes less BC break: methods not declaring a return type will > surely > > continue to work > > as before, and gradual migration it also supported > > - It has negligible run-time impact because diagnostics is emitted > maximum > > once per > > any method which misses the return type. If return types were inherited > > implicitly, > > incorrect return values would potentially trigger lots of errors. > > - It is more straightforward behavior than implicit inheritance, no > "magic" > > is involved > > > > Even though I prefer the current implementation (or its more lax > variant), > > I'm also not > > opposed to going with implicit inheritance if that's what we settle on. > > > > I appreciate any input, especially about the possible impact of the > > different approaches. > > > > Regards: > > M=C3=A1t=C3=A9 > > > > Is there any way we could make this mechanism more broadly available than > just for internal methods? This is a problem that also shows up when addi= ng > return types in userland libraries. > > A concern I have is that for methods with union return types, there > wouldn't be any way to avoid a deprecation warning without having PHP 8 a= s > the minimum version requirement. And given PHP's general error handling > story, deprecation warnings are not exactly graceful... > We have the same issue in Symfony. We have a special class loader that triggers a deprecation when a parent class has an `@return` annotation but the child class doesn't have a return type. Also, we don't trigger a deprecation when the child class also has the `@return` annotation. The reason for this is to allow child classes to be deprecation-free. By duplicating the annotation from the parent, child classes tell they know a return type should be added in their next major, which should happen before the next major of their parent class. PHP could adopt the same strategy using an attribute. When a method has that attribute, it'd mean the same: skip the deprecation regarding it's parent classes, and trigger a deprecation when child classes either 1. don't have an explicit or 2. don't have the same annotation. WDYT? --0000000000005555ff05b83e2fb3--