Problem/Motivation
When running on PHP 8.1, this module generates PHP deprecated function errors. Some examples:
Deprecated function: Return type of FieldChain::seek($position) should either be compatible with SeekableIterator::seek(int $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 12 of cer/field_object/includes/FieldChain.inc).
Deprecated function: Return type of FieldChain::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 12 of cer/field_object/includes/FieldChain.inc).
Deprecated function: Return type of FieldChain::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 12 of cer/field_object/includes/FieldChain.inc).
Deprecated function: Return type of FieldChain::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 12 of cer/field_object/includes/FieldChain.inc).
Deprecated function: Return type of FieldChain::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 12 of cer/field_object/includes/FieldChain.inc).
Deprecated function: Return type of FieldChain::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 12 of cer/field_object/includes/FieldChain.inc).
Deprecated function: Return type of CerFieldHandler::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 14 of cer/includes/CerFieldHandler.inc).
Deprecated function: Return type of CerFieldHandler::seek($position) should either be compatible with SeekableIterator::seek(int $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 14 of cer/includes/CerFieldHandler.inc).
Deprecated function: Return type of CerFieldHandler::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 14 of cer/includes/CerFieldHandler.inc).
Deprecated function: Return type of CerFieldHandler::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 14 of cer/includes/CerFieldHandler.inc).
Deprecated function: Return type of CerFieldHandler::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 14 of cer/includes/CerFieldHandler.inc).
Deprecated function: Return type of CerFieldHandler::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 14 of cer/includes/CerFieldHandler.inc).
Deprecated function: Return type of CerFieldHandler::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 14 of cer/includes/CerFieldHandler.inc).
Deprecated function: Return type of FieldHierarchy::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include_once() (line 8 of cer/field_object/includes/FieldHierarchy.inc).
Steps to reproduce
- Install Drupal 7 on PHP 8.1, using the standard profile.
- Log in as an administrator.
- Download and install the latest version of the CER module.
- Add an entity reference field to the Article content type, configured to reference nodes of the Article type.
- Add a CER preset with the Left and Right fields set to the reference field on the Article node type. Set it to Enabled and Bidirectional.
- Create and save a new Article content item.
- Check the Recent log messages report.
- Note the PHP deprecation messages.
Proposed resolution
Add the #[\ReturnTypeWillChange] annotation to these functions, so that they will be compatible with PHP 8.1 and also backwards-compatible with earlier PHP versions.
Remaining tasks
Patch and test.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
cboyden commentedSee attached patch.