Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116874 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20933 invoked from network); 12 Jan 2022 11:39:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jan 2022 11:39:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F0ED7180539 for ; Wed, 12 Jan 2022 04:48:39 -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.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NEUTRAL autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29169 217.70.176.0/20 X-Spam-Virus: No X-Envelope-From: Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 12 Jan 2022 04:48:39 -0800 (PST) Received: (Authenticated sender: contact@ll-experts.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id D932C60012 for ; Wed, 12 Jan 2022 12:48:36 +0000 (UTC) Message-ID: <8f6401a2-d307-2f22-a55a-2e250cb749da@php.net> Date: Wed, 12 Jan 2022 13:48:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Content-Language: en-US To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] how to add annotations to an extension function From: remi@php.net (Remi Collet) Le 12/01/2022 à 11:28, Brett McBride a écrit : > Hello, > I'm pretty stuck, trying to make an existing PHP extension > (google/protobuf) compatible with php 8.1 [1] whilst retaining > backwards-compatibility (ideally back to 7.0, but that might be > negotiable). I'm not a C programmer, and definitely not a PHP extension > developer. > Some methods in the extension implement Iterator and ArrayAccess, and with > 8.1 show deprecation notices, eg: > > Deprecated: Return type > of Google\Protobuf\Internal\RepeatedField::offsetGet($index) should either > be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the > #[\ReturnTypeWillChange] attribute should be used to temporarily > suppress the notice in Unknown on line 0 > > Given that the mixed type is new, I know I can't add it directly as a > return type without breaking BC, so my next thought was that I could try to > find a method that can create an annotation, and conditionally add it. On > php-general, I was pointed at the "zend_add_attribute" method, and I am > hopeful that something like this might work, if I knew how to call the > method: See the ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_* macros used to declare the method arginfo Ex: https://github.com/php-kafka/php-simple-kafka-client/blob/main/metadata_collection.stub.php used to generate https://github.com/php-kafka/php-simple-kafka-client/blob/main/metadata_collection_arginfo.h And with compatibility hack for older version https://github.com/php-kafka/php-simple-kafka-client/blob/main/metadata_collection.c#L44 Cheers, Remi > > #if PHP_VERSION >= 80100 > zend_add_attribute("returntypewillchange") > #endif > > Failing that, I'm after any guidance on whether anybody thinks this can be > done, or a pointer to some prior art I can borrow heavily from would be > amazing! > > Thanks in advance. > > [1] >