Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116309 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95145 invoked from network); 9 Nov 2021 08:37:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Nov 2021 08:37:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 703931804B0 for ; Tue, 9 Nov 2021 01:30:16 -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-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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, 9 Nov 2021 01:30:16 -0800 (PST) Received: by mail-ed1-f54.google.com with SMTP id x15so42900277edv.1 for ; Tue, 09 Nov 2021 01:30:16 -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=iHxBvK76piTtPqt58hZJ6dLN1ExOb51hZsmeFMR6RUE=; b=Qoi25qwMXOcbgMTmXj0T3kgy4CvBXOwRPR/XeRN7pqPcoDczWJAk0tt7nf+bWFK0/t SRJKNgXTcwIacJwlepZBSznhAiSiE/h4npEviuyi/yhKUAaPACp8zbQlDHZtdhnuAwXK C1hOsZAhhfhrTca0zbZ0819vrU4a4X9xk/VKKRRr9e8liJoQQXPKmQK34xq5+8BcJBDt xAjumMnNi00aqFMBA1Xl7rwXBNFNv9i97LaizWjRxZX+5m+4toITtlzdyDW/8iwUiH8m mnlk4JxHDN5iRJFkBn+tOXIgs0eot3aUNkd2XJSsb3lMW+eOX0kDycsVIMnpexwdGeHC +OWA== 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=iHxBvK76piTtPqt58hZJ6dLN1ExOb51hZsmeFMR6RUE=; b=6qqXZ45rOoP7d0p+k8PTNUG73zxDZ+Xl/L+RQ+nJULcWyxT++t4mHt6QRgo3WOMq2T zKNFGDOp37rtje8cobrG9IchuKqqPCohzfzB7lUF6YiEy7G1F6A76DfNSoBqOs/u9NWt aSnSOx39Fb/UkkRL4mDiYUhVAU70uARErRpl0jRRZVJOTMsF5po9xDsVOMZTwCNZW3uz wusA//G+5DQN2nS8SxgQ8thq+zJjaXfEb36+fijIEm6ClimNsqn5854ITc/2HVwFPg25 WZcZ8YIU4LrqVRQyvm9iPv9mT9+ad0hrjRu3e/juIBGj+j96znzR21bxLJbYczsIILZH e/rQ== X-Gm-Message-State: AOAM533xxAleF2vasnsZOcK2s+L8WAmVsKSRpSKNzfR3XuTCxekxAiVR 8e9yrfr5bwcL1DBBiSwtAagyNjQYE2tDlFlYFnk= X-Google-Smtp-Source: ABdhPJwCVK77mjSR1szaUwYnCBFl3ExdxE3GA19nua9alf8YNNsilVP3RMLz+JwwI2PiCdU0uZJD5jL35xESGaGdNtU= X-Received: by 2002:a17:907:90c3:: with SMTP id gk3mr7994191ejb.282.1636450214582; Tue, 09 Nov 2021 01:30:14 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 9 Nov 2021 10:29:58 +0100 Message-ID: To: Jeremy Mikola Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000bb9d9705d057c169" Subject: Re: [PHP-DEV] Automatic implementation of Stringable may conflict with old, untyped arginfo declarations From: nikita.ppv@gmail.com (Nikita Popov) --000000000000bb9d9705d057c169 Content-Type: text/plain; charset="UTF-8" On Tue, Nov 9, 2021 at 2:11 AM Jeremy Mikola wrote: > > https://github.com/php/php-src/commit/b302bfabe7fadd07b022ee30aacf7f41ab1ae0fa > recently added automatic implementation of Stringable ( > https://wiki.php.net/rfc/stringable) for internal classes. This introduced > fatal errors for each existing __toString() in ext-mongodb: > > ``` > Declaration of MongoDB\BSON\BinaryInterface::__toString() must be > compatible with Stringable::__toString(): string in Unknown on line 0 > Declaration of MongoDB\BSON\Binary::__toString() must be compatible with > Stringable::__toString(): string in Unknown on line 0 > ... > ``` > > Our arginfos for these methods have historically never reported a return > type, going back to when it was originally written for PHP 5.x. For > example: > > ``` > ZEND_BEGIN_ARG_INFO_EX(ai_BinaryInterface_void, 0, 0, 0) > ZEND_END_ARG_INFO() > > static zend_function_entry php_phongo_binary_interface_me[] = { > ZEND_ABSTRACT_ME(BinaryInterface, __toString, ai_BinaryInterface_void) > // ... > ``` > > I noted that _ZendTestClass (referenced in the original commit's tests) > uses ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX to declare a string return > type ( > > https://github.com/php/php-src/blob/eda9d7ac22c70f75a44bf33139acf8c812d69944/ext/zend_test/test_arginfo.h#L74 > ). > > While that's a trivial change we can make in ext-mongodb, I wonder if this > may have been an unanticipated BC break for third-party extensions. I > imagine ext-mongodb is not the only extension with older arginfo > declarations predating the introduction of type reporting in later PHP > versions. > Thanks for pointing this out! 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. In https://github.com/php/php-src/commit/86379b6710f972e0d4a11c89ce28d5768d9824d3 I have added a warning if this happens. The warning is only for master (i.e. PHP 8.2) to make sure that extensions add the type eventually, and we can drop this workaround. Regards, Nikita --000000000000bb9d9705d057c169--