Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108465 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1539 invoked from network); 11 Feb 2020 13:44:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Feb 2020 13:44:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7C226180537 for ; Tue, 11 Feb 2020 03:58:50 -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_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-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 03:58:49 -0800 (PST) Received: by mail-lj1-f181.google.com with SMTP id n18so11233722ljo.7 for ; Tue, 11 Feb 2020 03:58:49 -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=TDZbzzhtZ3RIB0nHS9kYuETijG4TMbUtSB0j6uPdv+g=; b=RhsZ5npch3+vFxbSt92fpQQ2IIZF9+AfV/KZjWNBP7vAA9YV6XAqvwBy9mvM9GQqIY rRl/YXtoGRtFcF9tdrVEhJijCJrvVPJGwiBSmQa5b8Gp//BaXrdhV4sbTkC6C93gxutq uyUb4NQulEbo6bi+GxlPBIQy5mbrBwi2P7C790LztX7NDL72wCNsBB1EF/gv0WyDsxj0 m2kI5QDJY7q4blddruIG19Vf2VkbwHQQm9JqPqLDmTgHnVXYj6CjiuugPQaZE3ZwZMZk iQqZN8cF/JZhZdEiLYU2zI0zDHrAD0Mk2OgwzMIKRPEe8/eJsROzj7Fwt8CDCDZiFSEb iLtQ== 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=TDZbzzhtZ3RIB0nHS9kYuETijG4TMbUtSB0j6uPdv+g=; b=R20ZuScoZEjYZAQo6zxTkThdkxhDaRwAzHl7Pd+nrtiltoUOMMnBD5xIbeHO4GByW5 X2vgYAvyqvOJSKfDVdAQClq8XNvGLWptbJI6/6vdm76UfGWIo+qPPiWTe2VaBMZKtfKj Iqvic2DQL0mT47ZbbSN0e78K9k+oFBkbF8PW2bOmmAqw+p3XsWq/Op/R9bZ5Gm4BKUMl tt8whayC5+Nhr4MkDwiIYPrlYGHmZE/drORNqwpiuRM9uAkYEMiHsCoyGYbSOdg1IhmD J/iN29pkkFQpc6KOfiZ3IHzZTuYYFNvwbvubLYQTydiOZu2Rar6eIOPW42Fw8ptb1tM+ xvkw== X-Gm-Message-State: APjAAAX8iADalZ23L5LbX538JyaHEvchfm0z3/eIUhDUf9ebdDnyGQJM Lp9LjhSiV9iB+ubuKSU9VmriEy4MPKl6htE/xWw= X-Google-Smtp-Source: APXvYqwub+ClDyI23kRQOvYEvPNwQwKRoowWlC3YFQLrvYzlCYUZGEk6BK4kZTwDFiKj4RJoFQ3u0xA2aIZIN8tmhHs= X-Received: by 2002:a2e:2a84:: with SMTP id q126mr3965092ljq.258.1581422326081; Tue, 11 Feb 2020 03:58:46 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 11 Feb 2020 12:58:29 +0100 Message-ID: To: Nicolas Grekas Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000fc7267059e4b93d1" Subject: Re: [PHP-DEV] [RFC] Adding a "Stringable" interface to PHP 8 From: nikita.ppv@gmail.com (Nikita Popov) --000000000000fc7267059e4b93d1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 11, 2020 at 9:57 AM Nicolas Grekas wrote: > 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, > you > >> 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 > have > >> too. > >> > >> Cheers, > >> Nicolas > >> > > > > I'm wondering whether it could make sense to automatically implement th= is > > interface for all classes that define __toString(). Explicitly > implementing > > the interface is useful for the transition period (where old PHP versio= ns > > 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 consume= rs > > of the Stringable type, it will likely be quite common that the interfa= ce > > will not get implemented... > > > > > This proposal has been implemented by Nikita himself on the linked PR, se= e > 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? > Just so someone has mentioned it... is "Stringable" really the best name for this interface? Reddit really didn't like it ;) Some possible alternatives: ToString, HasToString, CastsToString. Something to keep in mind is that there has been a recent proposal for "Arrayable" as well, and that had very different semantics (not about __toArray() at all). Regards, Nikita --000000000000fc7267059e4b93d1--