Problem/Motivation

\Drupal\Core\Datetime\DateFormatter::formatInterval() triggers deprecations in PHP because $interval is not always an integer.

Steps to reproduce

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

Proposed resolution

Fix in callers so we can add a typehint of int later.

Remaining tasks

User interface changes

API changes

Data model changes

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
Issue tags: +PHP 8.1
FileSize
704 bytes

Let's see where this breaks...

alexpott’s picture

larowlan’s picture

Status: Needs review » Needs work

Shouldn't there error say 'is not an integer' rather than string

alexpott’s picture

Status: Needs work » Needs review
FileSize
2.5 KB
3.77 KB

Some more fixes...

@larowlan this exception is here just to prove that eventually core is only putting an integer into this method - once we've done that this code will be removed and we'll rely on the PHP 8.1 deprecation.

The last submitted patch, 3: 3236798-3.patch, failed testing. View results

larowlan’s picture

👍

alexpott’s picture

Removing the exception. I wonder if we should trigger our own deprecation so code being run on PHP < 8.1 gets a deprecation. Not sure.

daffie’s picture

Status: Needs review » Needs work

@alexpott: Are you sure that you got all instances? Could you add a combination patch with the patch from comment #3 and comment #8? In that way we can see if we missed some.

All the changes is the patch look good to me.

alexpott’s picture

Status: Needs work » Needs review

@daffie the combination patch is #5 - see the interdiff on #8.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

  • catch committed 8e56a52 on 9.3.x
    Issue #3236798 by alexpott: \Drupal\Core\Datetime\DateFormatter::...
catch’s picture

Status: Reviewed & tested by the community » Fixed

I wonder if we should trigger our own deprecation so code being run on PHP < 8.1 gets a deprecation. Not sure.

I think we can leave this for when contrib tests are run against PHP 8.1 (probably a bit after 9.3.0 releases as long as we get through everything).

Committed 8e56a52 and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

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