Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108260 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 75858 invoked from network); 27 Jan 2020 11:19:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Jan 2020 11:19:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7E2DF1804F8 for ; Mon, 27 Jan 2020 01:30:04 -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=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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, 27 Jan 2020 01:30:04 -0800 (PST) Received: by mail-ot1-f51.google.com with SMTP id g64so7685053otb.13 for ; Mon, 27 Jan 2020 01:30:04 -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=FlHrk46qd57o9HW33derB2dIHkpvOQI9mY3NbQPkyFw=; b=dzlbbEdNJ0oHorwqVRPdNu2mQ+zO+9EMrIg+ZcI1PWRd+PfKA2iM2TQKqi/EOolK3z ac5dBT5PKSeUWPVPC8Ep+gTk+4xIPtl4QpNjcDJLUR+Ow0hFg80GIg0pVvycwz+CAYsy nO/OJ+ItGasp8i+qzLFYwtHjI436vn7L1rj61nKUlAvvi7vp0Hbw0ZCRDzghTqmLIK/b lPBHCh+hFWU2GzFS/lBqzUnUsyyOg/aUcA17awFW0qTDTODtuqQla269WuQIQmkaZBEP 5Ct/Spgf08GF9VSVmQ8aghkwE2eCUWBGaVAw6PXabcJl5cvzT3AejLtMylwU40EOBPXk b1PQ== 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=FlHrk46qd57o9HW33derB2dIHkpvOQI9mY3NbQPkyFw=; b=lt3RhaZBvOAdDQTUfX88SfQAfrx1Nx7Yc2LzJRQPqeoJtJBRJC6lXx7Az0HFx2/0+8 MVR5FKGBqn2j5EbtK9w/zB/EFLFcoYZWjEc+cMR4WPpFQJwDxI2L9Sj0iBXMIG7wNNAz PrXeVofqd/l4zTf3xriAoMSBZaQ1EBYcrvyMwLsGaQO9hNKY/LFX5jwJ8qsn6kmF9VhE y6cNlrhZiA/S7LAoLNGGCo1YVZ56dlyq9/W27JnMWmgNjOrfH9JJmijcAlu9I7QdhSMh hIpesD6D3mwFm8eURT9Lv85BxGCjWL2895w9dCuAkoXUCSi7kIhAt0nvTPptRfSSWuQM 5FRQ== X-Gm-Message-State: APjAAAWw806H16SfoqNNQ0qySfxnUX9OfcJir9kxr5vePJkuRaOLWkne vIirCBVNkrKxQGhnce1/3T2KKLpWEG8sSwl2bwLhiiTA X-Google-Smtp-Source: APXvYqzpOCyhNjw4xLCrsD1Bfz/1FpOhPcy0dkpICRkSImFGpS/SIg2xK7uTAfGLSRkSeBP83v1VMV0DxYVP2Ps5ClI= X-Received: by 2002:a9d:1d02:: with SMTP id m2mr11218715otm.45.1580117401932; Mon, 27 Jan 2020 01:30:01 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 27 Jan 2020 10:29:49 +0100 Message-ID: To: Nikita Popov Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000721b9c059d1bc074" Subject: Re: [PHP-DEV] [RFC] Adding a "Stringable" interface to PHP 8 From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000721b9c059d1bc074 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le lun. 27 janv. 2020 =C3=A0 10:19, Nikita Popov a = =C3=A9crit : > On Wed, Jan 22, 2020 at 4:47 PM Nicolas Grekas < > nicolas.grekas+php@gmail.com> wrote: > >> Hello everyone, >> >> as announced last week, I'm officially opening a discussion for adding a >> "Stringable" interface to PHP 8. >> >> The RFC and its rationale are presented here as required: >> https://wiki.php.net/rfc/stringable >> >> The patch is found on GitHub, where some discussions happened already, y= ou >> might be interested in having a look: >> https://github.com/php/php-src/pull/5083 >> >> TL;DR, I think we need an interface to allow passing objects with a >> __toString() method in a type-safe way, using the string|Stringable type= . >> Here is the stub of the proposal: >> interface Stringable { public function __toString(): string; } >> >> I invite everyone to review the RFC before commenting here as I tried to >> sum up considerations that some already had before and that you might ha= ve >> too. >> >> Cheers, >> Nicolas >> > > I'm wondering whether it could make sense to automatically implement this > interface for all classes that define __toString(). Explicitly implementi= ng > the interface is useful for the transition period (where old PHP versions > also need to be supported), but when considering only PHP 8 support, I > think it may make sense to implicitly implement the interface. If the > __toString() functionality also works fine without implementing the > interface, and there's probably only going to be relatively few consumers > of the Stringable type, it will likely be quite common that the interface > will not get implemented... > > Automatically implementing interfaces based on implemented methods could > also be a general language feature (see Go interfaces for example), but > likely not one we're interested in having in it's full generality. In thi= s > particular case, it seems useful though. > This looks like a nice improvement to the proposal, it'd be OK on my side. For the implementation, I might need your help to implement this logic, especially for extensions, since I suppose we'd like them to also have this behavior of implicitly declaring the return-type + interface when they declare the method. Could you please help me achieve that? Nicolas --000000000000721b9c059d1bc074--