Deprecated function messages on PHP 8.1

Created on 13 October 2023, about 1 year ago

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

  1. Install Drupal 7 on PHP 8.1, using the standard profile.
  2. Log in as an administrator.
  3. Download and install the latest version of the CER module.
  4. Add an entity reference field to the Article content type, configured to reference nodes of the Article type.
  5. 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.
  6. Create and save a new Article content item.
  7. Check the Recent log messages report.
  8. 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.

πŸ“Œ Task
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cboyden

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024