1

I'm trying to fix some php 8.1 deprecation notices in a PHP extension, which I believe involves either adding return type-hints (where possible, whilst maintaining some backwards-compatibility to php7.0), or adding a #[\ReturnTypeWillChange] annotation where the complained-about types (e.g mixed) are not available in prior versions:

Deprecated: Return type of Google\Protobuf\Internal\MapFieldIter::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in Unknown on line 0

I've read the relevant sections on the php internals book, and also php-src/Zend/zend_API.h to try to find a macro that will suit my purpose, but I don't see anything about return type-hints.

/**
 * MapFieldIter::rewind()
 *
 * Implements the Iterator interface. Sets the iterator to the first element.
 */
PHP_METHOD(MapFieldIter, rewind) {
  MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
  MapField *map_field = (MapField*)Z_OBJ_P(&intern->map_field);
  intern->position = UPB_MAP_BEGIN;
  upb_mapiter_next(map_field->map, &intern->position);
}

static zend_function_entry map_field_iter_methods[] = {
  PHP_ME(MapFieldIter, rewind,      arginfo_void, ZEND_ACC_PUBLIC)
  /* snip */
  ZEND_FE_END
};
1
  • I have half-solved the problem - you can type-hint a function's return type with the ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX macro: ``` ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() ``` Commented Jan 7, 2022 at 12:04

0

Browse other questions tagged or ask your own question.