Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116324 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27676 invoked from network); 12 Nov 2021 11:06:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Nov 2021 11:06:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7859B1804BC for ; Fri, 12 Nov 2021 04:00: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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 ; Fri, 12 Nov 2021 04:00:07 -0800 (PST) Received: by mail-ed1-f42.google.com with SMTP id z21so36679686edb.5 for ; Fri, 12 Nov 2021 04:00:07 -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=ta0tzjNZZApaOMGjJK48OCLH0Ax/p9v2Wyws/QtYyVY=; b=bDRE+WNbyqiDg+PCvhRtOfayyPcmZkSK26qT1T9vEz5PA4Al2zmlKyFEAItUALYbWQ jWdQ5TPxvWW9E9FJ4v9RwRSM4NySlgUIQeGjKOH3za8WG20Lj3KCDNq/rL6+TxhIeZlK Vo2wm9WQSZ6VURB9pYrWwcyMvIsoWyDfgR8d9JuLQ18yqth2YOP4oF1nNmvOJVRnXSsZ P++qxmBzPvkGtBO6E0sZxKmSYDEnvOlr9w0cx5y7O+JeUiTty6Gc+yf6DCF1NaZULyBN U37ZuaCLscdg/Rzrcv3bfCSsKczZKtfaDceSFDybZC5kxwKWUrL+9RWVJf2nY7y4jTt9 Tvhw== 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=ta0tzjNZZApaOMGjJK48OCLH0Ax/p9v2Wyws/QtYyVY=; b=MGJZhtP/gIttZHzVa6QZjYBR2KEbytNNvWcZNmzs9IOthGZgvIZ8TnlI4ZlyFXD36N YX1djfGnsaUQLtXJG5sKglI+fCFmXfth0pC/NI912U8rf0LBy3XVqZ/rpAEP6CGIZQvO 5eyR/3g10W4d7anKKYZYO5IhLUYIoN8PlfyYsNqbLMIBIpwn2baPjY8lcky1rQ08WHTQ rnYlyNJe/7kPLRNMIT+6moUAV4tA/4L08dQrakpSFoFYy1QC+EOoQZnldQe1KqCf3BTU L/2NuMivJnHoR49ghS4gPf7CqvhIX1MArpHzX3LDVCv4Ei8Dj/Rmhn1RLMGpQ4UcmZb7 9zvg== X-Gm-Message-State: AOAM532OhVcyOvCGXk3TAKpUVxZ0e4uXfSsKZ9Ts2AFUL+xKba3ph/db Fs9RCiti3QkfY/Ws9m5pjT3n83vCUPh22Fmkt3U= X-Google-Smtp-Source: ABdhPJzA0dioiRWsQ1aNNlpwQALNsgpiJ/kq91RtEZ4al+yC+N5EnZ0G+j9UQkLeqC1yiHjBiLBag9cG7MOoi30YIfs= X-Received: by 2002:a05:6402:50d4:: with SMTP id h20mr20329483edb.80.1636718405835; Fri, 12 Nov 2021 04:00:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 12 Nov 2021 12:59:49 +0100 Message-ID: To: Jeremy Mikola Cc: PHP Internals Content-Type: multipart/alternative; boundary="0000000000002d60ce05d0963354" Subject: Re: [PHP-DEV] Automatic implementation of Stringable may conflict with old, untyped arginfo declarations From: nikita.ppv@gmail.com (Nikita Popov) --0000000000002d60ce05d0963354 Content-Type: text/plain; charset="UTF-8" On Wed, Nov 10, 2021 at 10:13 PM Jeremy Mikola wrote: > > > On Tue, Nov 9, 2021 at 4:30 AM Nikita Popov wrote: > >> >> In >> https://github.com/php/php-src/commit/a551b083073ea08f8fc53b0e1a6380b6de26cc6b >> I've added a hack to add the string return type if it is missing and thus >> make the signature compatible with the interface. That should address the >> immediate compatibility issue. >> > > Thanks for the quick fix. > > A related question that came up, and is most likely unique to ext-mongodb, > follows. Many of our classes with toString() methods also implement a > corresponding interface with a toString() method. For example: > > * https://www.php.net/manual/en/class.mongodb-bson-binary.php > * https://www.php.net/manual/en/class.mongodb-bson-binaryinterface.php > > I'm in the process of adding explicit return type info to _all_ of our > toString() arginfos (classes and interfaces), but a thought occurred to me > that doing so may be a subtle BC break for userland classes implementing > these interfaces, since an explicit string return type would then become > necessary. But if I only modify our classes and leave our interfaces as-is, > PHP rightfully reports an error because the class' toString() method cannot > conform to both Stringable (with type info) and our interface (without type > info) -- at least PHP versions before 8.1.0RC6. > > Reading the patch above, it looks like the automatic Stringable > implementation only kicks in when the arginfo has no existing return type > info. In that case, I think the only option to completely avoid a BC break > would be to continue to leave our return type info omitted (on both our > classes _and_ interfaces) and allow PHP 8.1+ to apply it automatically. Is > that correct? > 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.) Regards, Nikita --0000000000002d60ce05d0963354--