Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108452 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 61980 invoked from network); 11 Feb 2020 10:43:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Feb 2020 10:43:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0E75B1804D7 for ; Tue, 11 Feb 2020 00:56:54 -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-f50.google.com (mail-ot1-f50.google.com [209.85.210.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 ; Tue, 11 Feb 2020 00:56:53 -0800 (PST) Received: by mail-ot1-f50.google.com with SMTP id 59so9297109otp.12 for ; Tue, 11 Feb 2020 00:56:53 -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; bh=wXCVqpbAov6kw9/byBzTWQ/DdXuppwvPCqUuB5x/xQg=; b=csg2XHULhzbgxVOX2R3fqeXKFdzU+qNQ9tUQ1TYVsy1XwHihV4gEj8mlGKesKOAG7T g4kyo+UmGb014+LA0d1gsxiCTq3IQqj9qIuCunxET2dPvNuoPoYt/WyoyOrOR+3Xh9R7 wPWk28nldYHycan1C5rr4hYuBmyD482EQIzRm9lSEE+lXy6+7s/wCXAbI+s4dD3MPuew jDH/5Sry6JWwisEyiAn4J8NnPjEJmUi0hqviKBK5quzQqcGdr3xFxEczKNrrvFw/x2eU qijUWbSV+LlOISPmrwn7JjdSEKUUny749fMymn1mrCtgZOVjd2mu+jHzEq57VSLT12JG SJ6A== 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; bh=wXCVqpbAov6kw9/byBzTWQ/DdXuppwvPCqUuB5x/xQg=; b=kRJhcqcNIzAYdtm8QcuhbVJDdn8nI7pwndxdiA13ugD4S8671oAD6FyPmJOdkAkLBj uYnTiM+XZBktr6/bcJ9G4RAlGGuoreBoCthI2lBw7X1jPXrhrhwh10r4keGaXwKcY1p0 eg/pt8GQFXm9BeamMXNHV9wCX8tXcPqWUQPQpkgrs1hsEEGJSa6mpHNI8WapxX9FWzQU jhTt0fiYTMavuJf+obptv56FdEPmzEe+uLjSqWXAQ8VB36Drdr4focr17Su5L3cYGXe/ dveinX1zbKB5VrAH+Gg7IgD+b3PiZpjL5F2TkzKwKmZy5Jg2qHWhdwRcbX69xoT76iBL 573w== X-Gm-Message-State: APjAAAVObrvK0f9m/uQxTnj8OyI1J+wM5MFqZGhxn4Sok0/lvpfCGLdC xE/LP8H0s72Tq+mhkmFJwBYo9K43oqXWPl6JMnx5t3urki0= X-Google-Smtp-Source: APXvYqwcPQW2/A9Re/9qgrf1UNCRJPP45G9hWqKRPFiVniLHqi/FGyao7GsV3IqDNlinAJZJqswjTETF5QijCM/8Sok= X-Received: by 2002:a9d:32f:: with SMTP id 44mr4273258otv.234.1581411410594; Tue, 11 Feb 2020 00:56:50 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 11 Feb 2020 09:56:39 +0100 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000005f511a059e490943" Subject: Re: [PHP-DEV] [RFC] Adding a "Stringable" interface to PHP 8 From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --0000000000005f511a059e490943 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... > This proposal has been implemented by Nikita himself on the linked PR, see 2nd commit: https://github.com/php/php-src/pull/5083 I updated the RFC accordingly: https://wiki.php.net/rfc/stringable I think the RFC is ready for entering the voting stage. Any other comments before? Cheers, Nicolas --0000000000005f511a059e490943--