Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116589 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38005 invoked from network); 8 Dec 2021 15:01:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Dec 2021 15:01:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6121D18053B for ; Wed, 8 Dec 2021 08:01:56 -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.7 required=5.0 tests=BAYES_05,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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.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 ; Wed, 8 Dec 2021 08:01:55 -0800 (PST) Received: by mail-il1-f169.google.com with SMTP id w4so2554514ilv.12 for ; Wed, 08 Dec 2021 08:01:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eSwU3DJbBcoST5iOa94CEgX99j0E/pJGxf3aMUdwcH4=; b=JpuxK7Nawe9/wZ7a/nMcZFDa5YvdYJw7IOJN8zzUiTeX6ltjECNnGuY23zith6toCv DRRD2HMfcB6P3gnRQTQg27CAJxlk5F3yOizlsePinNoCyBLOZ8zN7MazU0svh/oYyJTG hKusKaWajnrN8zwXL0xWgMUWjavmaS1YQEuS3+q2x5bDTOkQBf2L2N5G8//TY4o7MKud qSQGxANpLXok1hQAyZeGaZ7rc97CuNF2u/0bn9n39KEHGb4Az/ezkB4FoyYaJWa6BpvS BPJJxhDNaj9TBcihGrw95DpEAeNPzulbopxL3Jw9mrqzBlh7+pDp23JQGgwGdyof85Ed CPWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eSwU3DJbBcoST5iOa94CEgX99j0E/pJGxf3aMUdwcH4=; b=2ewR2c9zU8Um2Cyu2vxMEOer1QJ7S81gBb/r5MoNmT8ZYLkaapw9vCeaKd3ZV0W5Bs q4GdNbaYHxedjhv2C24KJQffY+CNOSjberOLee11Rnz9eElZGMstV9hMiXOjMj3MFDzI dmhRtCTb9g5tJKt2jHQEy2V1khHMGbOrYTTcNE8XZrXpyGv6Fy39+XMlBTLi90DaHiRL COjkOFVsokG1oFNvjGGFtQfm0dnheMACxfclgSmNAk01WrJ2MMZPl8zQUmu/XgZjJVXc daxz7iVqJw6na5dYe8XOQbzZP/lDQIRK+0XDDCkV0sQxH1BE3w7WXeDNzJt7DmL6SA/U 7jMg== X-Gm-Message-State: AOAM532pa2d4u405+gi3ke5q/5alu/Zp+nPPNPiNkXEmGY92lbWeNpug qYrn+zotNxgrpcYRze1kJXbo6v3Vqo8PzxufvE0/dV7kkUU= X-Google-Smtp-Source: ABdhPJwrdsnkBtoYrjnQ7vpcGLtUzsX3iqRGn8Ydsj2GAGayqQ8qGH4D6SfUvc+jUtgrBq4sR3s13TXsGKN7xLyrgzU= X-Received: by 2002:a92:cda6:: with SMTP id g6mr7536676ild.83.1638979315279; Wed, 08 Dec 2021 08:01:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 8 Dec 2021 11:01:43 -0500 Message-ID: To: Nikita Popov Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000e1acc805d2a49b80" Subject: Re: [PHP-DEV] Automatic implementation of Stringable may conflict with old, untyped arginfo declarations From: jmikola@gmail.com (Jeremy Mikola) --000000000000e1acc805d2a49b80 Content-Type: text/plain; charset="UTF-8" On Fri, Nov 12, 2021 at 7:00 AM Nikita Popov wrote: > > With the introduction of Stringable PHP also started automatically adding > the string result type to __toString(), specifically for compatibility with > the interface. As such, it should be safe to add the string return type > everywhere for PHP >= 8.0. (If you use stubs with legacy arginfo, that > would automatically give you the right behavior: types on PHP 8, no types > on old versions.) > We haven't explored using stubs, but I'll keep that in mind. Andreas has definitely mentioned that in the past and I believe it's on the list of ideas to implement once we revisit typing across the board for the extension (which we plan to do since we finally dropped support for PHP 7.1). I previously added explicit string return types to all of our toString methods (including interfaces), which I understand is a small BC break for any userland classes implementing those interfaces (as rare as that is). Just yesterday, I had an idea to use tentative return type info on the interface toString methods ([mongodb/mongo-php-driver#1283]( https://github.com/mongodb/mongo-php-driver/pull/1283)), which seems to require no changes at all to userland classes. ReturnTypeWillChange attributes are not even required on PHP 8.1+ since the Stringable behavior will automatically add the return type info if it's omitted. For PHP 8.0 and earlier, we map the ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX macro to ZEND_BEGIN_ARG_INFO_EX -- so these methods will continue to have no return types there (also avoiding a BC break). I tested the change (i.e. tentative return type info for interfaces) with PHP's master branch to cover the warning you added in [86379b6]( https://github.com/php/php-src/commit/86379b6710f972e0d4a11c89ce28d5768d9824d3). There seems to be no conflict, which seems reasonable considering that return type is only "tentative" from the context of userland (and only until PHP 9.0, when it becomes enforced). Tentative return types are still considered the actual return type for internal purposes and satisfies the check for Stringable compatibility. Are we likely to run into issues with this approach? If so, I'll consider your last suggestion to define non-tentative return type info for interfaces on PHP 8.0+ (where Stringable will add it to userland classes automatically), and leave return type info absent for PHP 7.x. But if both are viable solutions, I think I prefer the tentative return type info approach. -- jeremy mikola --000000000000e1acc805d2a49b80--