Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112781 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33144 invoked from network); 6 Jan 2021 16:02:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2021 16:02:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 216F31804F6 for ; Wed, 6 Jan 2021 07:39:00 -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=-0.2 required=5.0 tests=BAYES_40,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-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 07:38:59 -0800 (PST) Received: by mail-lf1-f44.google.com with SMTP id s26so7421123lfc.8 for ; Wed, 06 Jan 2021 07:38:59 -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=mRjSwk2sWdtHyG54Yv+PMbmUxc5Ub7zZAJ1XntgwGUM=; b=JnhZfcobdAsW1UEA8aje/62q3JMFFGQM9G8psvIXqut9n2cX7IAQlHBoqnCOlE0Axn ZM4nfJyfMqi3n6U9qYVAnj8IndSfwvpsRal2q8BLYBXw0OU9/2mJKkAprPTdS4kVdn8k 0HAAieaIWAOZMUHOw1NoVpbqnPnk61fCDIevwiu4HV4rr0bnsRzSHop3ND+1/1QIewd5 NHw1dKrLVKs+glX6TeJzIJ/ZCMZ5pcCHUYcBiBhwMHSQ2e6nEAvHpBncH0SRWbxOt4Sh LUt1ZaN+NypyCgoBrq8iFB/3lT/NIBWqZJr1rZ1vdAa2iF96shlDrONSqB8TKXzVfRzQ shBw== 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=mRjSwk2sWdtHyG54Yv+PMbmUxc5Ub7zZAJ1XntgwGUM=; b=jKizyEDVisrR16Sa+8Yq5YXPjfK8XVeO2DpZMHF+53P8APGTQVsvh5SmwCK4MX96gc vV+5y93AeUwU2xOUTAwavfcntJ34hEyg8q/N5V83O6CyEI1mJuGC26XFnb0vcae/jxHB v4M/xKboO76pa5nkf4vpgyb0X5r12zbWkwNW9mHjyohH6g5A3zWWwXbubNL4gYL45MhB vbz8WQes33sgnJOi7GGB9p9BKKX2v/HWoENI6iVG33wAYBbP1zvnE05NCPayjjKY4i5h IRCKcK/rp/oICvhBWebC1OVbEaJHpkB5o30gIisHZvUK+NpTLpfDy1rpZ942tbo7Rblw bIgA== X-Gm-Message-State: AOAM532g/lOaL2HyI8Qh1tIZDE1OOQH5YGP1hDQn5M6U3sO8Pg2VuGQg nfgWy7sycgBCoZSY45YNxNzvyuCuG4/pNq6//v8= X-Google-Smtp-Source: ABdhPJxr7BypdJ63J07uY43BUHJ+jBrXgzLfQ8wsBMZS8WZWTDe6Gq4v/jJx6va1nEeoLHzU3Asd63diZPlKAZbbihg= X-Received: by 2002:a2e:8eda:: with SMTP id e26mr2163873ljl.272.1609947535534; Wed, 06 Jan 2021 07:38:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 6 Jan 2021 16:38:39 +0100 Message-ID: To: =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000f66d5405b83d1e30" Subject: Re: [PHP-DEV] [RFC] Adding return types to internal methods (PHP 8) From: nikita.ppv@gmail.com (Nikita Popov) --000000000000f66d5405b83d1e30 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 inheritance > 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 declare= s > 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 surel= y > continue to work > as before, and gradual migration it also supported > - It has negligible run-time impact because diagnostics is emitted maximu= m > 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 "magi= c" > 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 adding 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 as the minimum version requirement. And given PHP's general error handling story, deprecation warnings are not exactly graceful... Regards, Nikita --000000000000f66d5405b83d1e30--