Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113170 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4835 invoked from network); 13 Feb 2021 22:08:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Feb 2021 22:08:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E38FB1804B1 for ; Sat, 13 Feb 2021 13:55:02 -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.4 required=5.0 tests=BAYES_05,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-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 ; Sat, 13 Feb 2021 13:54:59 -0800 (PST) Received: by mail-lj1-f169.google.com with SMTP id a22so3352568ljp.10 for ; Sat, 13 Feb 2021 13:54: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=APXqisiDk8ryylyfmOq3tPgDubjXUPjeWOPe6M/JwYQ=; b=Ck4m3jFJOLkF23nVU4Cti6URWB/0IABUVN6tBBi+Kp2ppnhpyrZBXvf/RkTkvDcjhF tjuR1l0/2Q6geqVkdnt/S8Wm/NQMN+Ddo8IC1HHHhxtrosHMIXuuZNEp1QIRNwGIkk82 1sEIDAJ1pXobdNw/1F41+phQl1/WKmQA0eVyVpPSHugv9Gr2h1wt4UHlXh8Oxf9+vDAG 3E+vN/LaatjHCIkUIpoicSCIP6y+4LaHLEVIsQSt3L6tDw8jrhgg51i7D/nmnLa7nASx S0xhD6ZdhfZh5UIfHNaeqDyBjd3XREXqMP+TqYxlEtbT22IfJHZCq5Rtil70UdUf85qC YIgA== 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=APXqisiDk8ryylyfmOq3tPgDubjXUPjeWOPe6M/JwYQ=; b=pspJR7KGYQUMbfcYtpFHRLIbJw+tuBI4wYnnEbpXAwmbw5ZlYCHPoQB8Ntc5WM4Kdu PJYZgSEG2RRbmT2ICm+ncOhSx6dIkhJGgTI90kuhIOwtrv0HP7EHcjgeKxQD1cnr8rss WZm8fRCO7rh6dUvIfkv/2PKRhn2dD8zQgb4j0pq5Ei9Nbq/6NWuHKbwBjM2ykz/BWSXI gwrsjOGg5dzXx2IEPAEJ5q7K0xWEQtoH+xNhZc6EZLAIO9IjQ9YFbyPerRjIoptxh86u hm2suljWQNp5iDlw8zxxMAt5eI0YLKoWI1smaUq+ma6ZW7jMhvPPHK5lfh+DlXlBNHhn br3w== X-Gm-Message-State: AOAM531oKdAgY1q48x46onTVh+Runng2vty5lTp0YtvN0EQmJtFuRLMs F9IMKTPA1m25OkuJsGIL2/bnneNqPPWSm16nwRw= X-Google-Smtp-Source: ABdhPJwASKvUvHOc2GfFg9T7WzFsrg/50/R8iwepngw5WfchdxTIdN2PrQogVIOUu20rPFOnYpOoCPe78cfv+iUNmqk= X-Received: by 2002:a05:651c:1130:: with SMTP id e16mr1591240ljo.227.1613253297704; Sat, 13 Feb 2021 13:54:57 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 13 Feb 2021 22:54:46 +0100 Message-ID: To: Nicolas Grekas Cc: Nikita Popov , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000be11ad05bb3ecd33" Subject: Re: [PHP-DEV] [RFC] Adding return types to internal methods (PHP 8) From: kocsismate90@gmail.com (=?UTF-8?B?TcOhdMOpIEtvY3Npcw==?=) --000000000000be11ad05bb3ecd33 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Nikita and Nicolas, After a month of pause, I came back to this topic. 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... > Thanks for pointing out this possible consequence. I do agree that it's a valid concern, so we should try to do something about it. I could come up with a few possible mitigations so far: - instead of E_DEPRECATE, we could emit E_STRICT warnings so that people can separately tackle this class of errors from the rest - we could add support for a SuppressReturnTypeDeclaration annotation that could suppress these notices altogether - we could postpone the tentative declaration of those method return types which can't be expressed on PHP 7.4 to a later version (e.g. PHP 8.4) when the 7.x series will have become EOL for a while Actually, I counted how many of the return types in question can't be expressed on PHP 7.4. I found ~270 results out of all the ~1440 methods which don't yet have a return type declared. Do you think these ideas would sufficiently answer your concerns? 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. Inspired by Symfony's strategy, a #[ReturnTypeDeclaration("int|string", "Library Foo v2.0 will declare int|string as return type")] attribute could be added to methods in order to gradually let any child classes know that a future version of library Foo will declare the int|string return type for the method in question. Then overriding methods should either declare some kind of return type (unfortunately, even a wrong one would suffice, since it would be cumbersome to store exact type information in an attribute, if I'm not mistaken) or add the very same attribute - but at least the first argument should be exactly the same, from character to character - if people want to avoid the deprecation notice. It has just come to my mind that in case of internal functions, we could combine the annotation based approach described above together with the behavior I originally proposed: - if an overriding method declares a return type then the regular compatibility checks would kick in, and a notice would be emitted in case of failure - if an overriding method doesn't have a return type, but a ReturnTypeDeclaration attribute, then a notice would be emitted if the attribute doesn't have the exact same type as the one we added via PHPDoc in the stubs - otherwise a notice is emitted To be honest, this migration path seems to be slightly overcomplicated for me. So personally, I would be just fine with the ideas I collected in the beginning of my message for reducing impact. However, if you think that it makes some sense, I'm ok with going with something along the lines of it. Regards: M=C3=A1t=C3=A9 --000000000000be11ad05bb3ecd33--