Problem/Motivation

_color_pack() can cause deprecations on PHP 8.1 due to passing a float into something that expects an int.

Steps to reproduce

Run \Drupal\Tests\color\Functional\ColorTest on PHP 8.1
See https://3v4l.org/mO09G

Proposed resolution

Cast the value to an integer.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3240176-2.patch557 bytesalexpott

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new557 bytes
alexpott’s picture

Issue summary: View changes
andypost’s picture

Status: Needs review » Reviewed & tested by the community
$ vendor/bin/phpunit -c core/phpunit.xml.dist --colors=always --debug -v \
core/modules/color/tests/src/Functional/ColorTest.php
...
Runtime:       PHP 8.1.0RC3
Configuration: /var/www/html/web/core/phpunit.xml.dist
...
1) Drupal\Tests\color\Functional\ColorTest::testColor
Exception: Deprecated function: Implicit conversion from float 34.999999999999986 to int loses precision
_color_pack()() (Line: 778)
...
2) Drupal\Tests\color\Functional\ColorTest::testValidColor
Exception: Deprecated function: Implicit conversion from float 34.999999999999986 to int loses precision
_color_pack()() (Line: 778)
...
3) Drupal\Tests\color\Functional\ColorTest::testOverrideAndResetScheme
Exception: Deprecated function: Implicit conversion from float 36.97003612089514 to int loses precision
_color_pack()() (Line: 778)

After patch test pass (the related deprecations could use other issues)

Unsilenced deprecation notices (289)

  281x: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated
    104x in ColorTest::testColor from Drupal\Tests\color\Functional
    91x in ColorTest::testValidColor from Drupal\Tests\color\Functional
    63x in ColorTest::testOverrideAndResetScheme from Drupal\Tests\color\Functional
    23x in ColorTest::testLogoSettingOverride from Drupal\Tests\color\Functional

  4x: Return type of GuzzleHttp\Cookie\CookieJar::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
    1x in ColorTest::testColor from Drupal\Tests\color\Functional
    1x in ColorTest::testValidColor from Drupal\Tests\color\Functional
    1x in ColorTest::testLogoSettingOverride from Drupal\Tests\color\Functional
    1x in ColorTest::testOverrideAndResetScheme from Drupal\Tests\color\Functional

  4x: Return type of GuzzleHttp\Cookie\CookieJar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
    1x in ColorTest::testColor from Drupal\Tests\color\Functional
    1x in ColorTest::testValidColor from Drupal\Tests\color\Functional
    1x in ColorTest::testLogoSettingOverride from Drupal\Tests\color\Functional
    1x in ColorTest::testOverrideAndResetScheme from Drupal\Tests\color\Functional

  • catch committed c804f14 on 9.3.x
    Issue #3240176 by alexpott, andypost: _color_pack() can cause...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed c804f14 and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

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