Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112625 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24527 invoked from network); 28 Dec 2020 19:20:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Dec 2020 19:20:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 698C71804C6 for ; Mon, 28 Dec 2020 10:54:24 -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.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, 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-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 ; Mon, 28 Dec 2020 10:54:23 -0800 (PST) Received: by mail-lf1-f50.google.com with SMTP id b26so25891878lff.9 for ; Mon, 28 Dec 2020 10:54:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=etdvaWD8IngeeRGu25hCAZXeRlH9pNk8t28elp0q0/E=; b=VsDWMpcj8YJjO2BE3km7bstZVIuypW7bArSDGh+C/zv3zoDAiRZTuaKYuq87qTX0ic f73QbSxIJ6wL+C/TMZ+m7l1sZzTPhuPc/QbACdklUs4ZsZdBlOgwbnX3VpWLlJhr8cDY gr2AD3phiWsjPaTUNh9E85F6QwGsdB3pQhbfH0+HVkID609R7YOEZMu0G+XaZnwmFgIy JQWEaC8gEnpl7j7u790/mbMG22OyTJV4zekmG9i8xmmoMw+K90Oq2GNVhdxOftXusCiA ZYNyXkbxzGxwZErYVrmh6xNdhwSFvtkkGkwk7GYcKEXAGArjIJJ0rVWJeO7sfK2kEpsC o9fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=etdvaWD8IngeeRGu25hCAZXeRlH9pNk8t28elp0q0/E=; b=VLAqLvm0Y4vdf4hEmVsVjz6kSUpGktuEsVL6wPuG1zFVJwcdRKB5WMEhH9oYrjDt1K 3yL6oFUap16YfpdcXJTIJiIbZ+TyVyjDwzIvqPx3vKGEa173Jy9IcX1I6/DilzEzZkdd uypoFkNM91Xmaet9gF+PI+pkQF1YupOWBMr7cFbBiY+XHfNjYcWZGS/RR+pfhndd076U 48kThBmfsXxCXCgJ5YG5VOM6i75SYVyUg1IFUIEOWpeDia09WUf36rHMIPl33v0Na31z 1jGnDpInL5KT/55C4wpagwK2YtqovkY/T4FjJhJ3SkdUHz8FraJKdTRcLBorVN5L5UL5 zMfg== X-Gm-Message-State: AOAM532xoTrT7Q9Cr780G8JXEwxio0Sj1yHWHOsIKv5Y1u8movPOhCsQ osurgOi9h6+gFBbQ4nFdKghIsHwC8l582a0f/VV+TaPnpkQ= X-Google-Smtp-Source: ABdhPJwtAN9gvqzYtNU2tbuHnIorleMWbqNgU/SW9B5j3n8OZnwto0syLkJYPOoMsuLzthpZMvh+Fdf0N5B/SRaP+oM= X-Received: by 2002:a2e:8416:: with SMTP id z22mr23463896ljg.347.1609181660151; Mon, 28 Dec 2020 10:54:20 -0800 (PST) MIME-Version: 1.0 Date: Mon, 28 Dec 2020 19:54:09 +0100 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000003b818b05b78acd49" Subject: [RFC] Adding return types to internal methods (PHP 8) From: kocsismate90@gmail.com (=?UTF-8?B?TcOhdMOpIEtvY3Npcw==?=) --0000000000003b818b05b78acd49 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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 --0000000000003b818b05b78acd49--