Problem/Motivation

\Drupal\Core\Datetime\Element\Datelist, \Drupal\Core\Datetime\DrupalDateTime and \Drupal\Core\Datetime\DateFormatter::formatInterval() all trigger deprecation notices in PHP 8.1. Handling them together because they are all in the same component.

\Drupal\Core\Datetime\Element\Datelist::checkEmptyInputs() results in deprecations because it passes non strings in strlen(). $input['object'] is set to the date object and should not be checked.

\Drupal\Core\Datetime\DrupalDateTime::format() passes $format to preg_replace_callback() after calling \Drupal\Component\Datetime\DateTimePlus::format() which can result in $format being set to NULL if there are errors.

Steps to reproduce

See test runs on #3220021: [meta] Ensure compatibility of Drupal 9 with PHP 8.1 (as it evolves)

Proposed resolution

Avoid calling code that expects a string with NULL values.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
3.82 KB

Here's the working fixes from #3220021: [meta] Ensure compatibility of Drupal 9 with PHP 8.1 (as it evolves) - I'm unsure of the fix to \Drupal\Core\Datetime\DateFormatter::formatInterval(). Ideally we'd be able to change the typehint on this param to int so I think maybe we should fix this in the callers...

alexpott’s picture

alexpott’s picture

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me

  • catch committed 1d75ddb on 9.3.x
    Issue #3236796 by alexpott: Fix PHP 8.1 deprecation errors in Drupal\...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1d75ddb and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.