Problem/Motivation

\Drupal\Component\Utility\Random::image() triggers deprecations in PHP 8.1 because we're passing floats into parameters that expect integers.

Steps to reproduce

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

Proposed resolution

Refactor the code so this does not occur.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

N/a

CommentFileSizeAuthor
#2 3233015-2.patch1.19 KBalexpott

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
Issue tags: +PHP 8.1
Parent issue: » #3220021: [meta] Ensure compatibility of Drupal 9 with PHP 8.1 (as it evolves)
StatusFileSize
new1.19 KB
longwave’s picture

Status: Needs review » Reviewed & tested by the community

Casting the values is an easy fix, as these are randomly generated images I don't see any accuracy issues from doing this.

alexpott’s picture

as these are randomly generated images I don't see any accuracy issues from doing this.

Well the casting is already happening internally in these built-in methods. There's no half pixels :)

longwave’s picture

I was thinking should we cast or round $x first and then use the integer value in the later calculations that use the variable, but in this case it's not worth thinking about :)

alexpott’s picture

@longwave good point. The approach in the patch maintains the current behaviour and as this is for random images I agree - let's save the brainpower :)

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed 749dd1d and pushed to 9.3.x. Thanks!

  • larowlan committed 749dd1d on 9.3.x
    Issue #3233015 by alexpott, longwave: Refactor \Drupal\Component\Utility...

Status: Fixed » Closed (fixed)

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