Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108258 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71998 invoked from network); 27 Jan 2020 11:09:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Jan 2020 11:09:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2C46B1804F3 for ; Mon, 27 Jan 2020 01:19:25 -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,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 ; Mon, 27 Jan 2020 01:19:24 -0800 (PST) Received: by mail-lj1-f181.google.com with SMTP id h23so9821232ljc.8 for ; Mon, 27 Jan 2020 01:19:24 -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=JO/iXIoEYSlzaav+4SEAzGAkywgu/XEBDbE8roV/+Ek=; b=TSFqstWV3MedLjLqYL/a2IqUniD8R6M+86FvDV6X0Vy1YRD2vxDqy1C5UiUyILfq+1 e/tUNFaVb+CdY2QkqJcsGItLjqU4fYK47x/xUXxvkNaxZvkXE6gZXeMBtrOHBRDTtEn6 9he0lev3vCSKN3TsNYl8auxepFrQ2cCEm6pBBKH/SzSRJsn4SpnS/CkWCm8BejAXuTt5 GFYCeQdF1qgxk4lAidnpNzo2greEmi59MaiplxCGZrodMJi50mD1N5OrWaUwDHKtSEUz N86M3HHC7EjW9T//kTmqy/dmleq9c343L7vMBsebak9JFbrAy6fzRy+HmrBlAgmDqC0M EEoQ== 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=JO/iXIoEYSlzaav+4SEAzGAkywgu/XEBDbE8roV/+Ek=; b=XhXa0qyHiAhMINL5E1iSEINZVgYO/jW1ZENeLYaeHyIncO1rbKrD4Lr69mecinTwuM 6hrGscR/YYNBvhuZklD6BggTn7DJZdN3vAPfZXLT1vRXf7pbGx+rhY0fwqieGmp9+jGK mS2neOcDvN3+mS7qgc14154ZjSL7RgurBavIMhCxrjLWQyo4MzM1xm2/jgiZapDGRAp0 ts+6sXcMlqel6Iorb7q1vaS/xdFWton9MIUcrUNkXCUK/DD2EgDDQeNe67cz1OlwEF/K AsVjN+C5oz2YarPNRV+tv2wWnKF8z0e2tuQ4gRTAQJY1pAbSYz1gKpA/agzaCJyUUANn tJQA== X-Gm-Message-State: APjAAAURxroAXk9Gu4gRazHF52bstXHucKU2Z+j+8xoi2dyuJSKkd70s 5nm1TRNsrqpSru9MMkCSNK+W0+U3HmthEJH7m+g= X-Google-Smtp-Source: APXvYqxasOeFlEELvTaaASedAn+VsWOS5YI9rT6QRhG/49PB6UrE9JpPi+FL6aYkCucbA9nUBlofmiSw0hQ+CB06w38= X-Received: by 2002:a2e:2a84:: with SMTP id q126mr9363619ljq.258.1580116762268; Mon, 27 Jan 2020 01:19:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 27 Jan 2020 10:19:06 +0100 Message-ID: To: Nicolas Grekas Cc: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000005197ed059d1b9aca" Subject: Re: [PHP-DEV] [RFC] Adding a "Stringable" interface to PHP 8 From: nikita.ppv@gmail.com (Nikita Popov) --0000000000005197ed059d1b9aca Content-Type: text/plain; charset="UTF-8" On Wed, Jan 22, 2020 at 4:47 PM Nicolas Grekas 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 this interface for all classes that define __toString(). Explicitly implementing 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 this particular case, it seems useful though. Regards, Nikita --0000000000005197ed059d1b9aca--