how to add annotations to an extension function

From: Date: Wed, 12 Jan 2022 10:28:08 +0000
Subject: how to add annotations to an extension function
Groups: php.internals 
Request: Send a blank email to internals+get-116873@lists.php.net to get a copy of this message
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: #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] <https://github.com/protocolbuffers/protobuf/pull/9370>

« previous php.internals (#116873) next »