PHP8.1 deprecation notice

Issue #156 resolved
Christian Abila created an issue

In v4.1.0.2, if using PHP8.1, opening the site-administration with debug set to NORMAL and higher, the following deprecation notices are shown:

Deprecated: Implicit conversion from float 304.00000000000006 to int loses precision in /moodle/course/format/tiles/settings.php on line 198
Deprecated: Implicit conversion from float 305.00000000000006 to int loses precision in /moodle/course/format/tiles/settings.php on line 198

Possible solution: explicit type conversion

// Tile title line height.
    $choices = [];
    for ($x = 30.0; $x <= 33.0; $x += 0.1) {
        $choices[(int)($x * 10)] = $x;
    }

// Tile title line line padding.
    $choices = [];
    for ($x = 0.0; $x <= 6.0; $x += 0.5) {
        $choices[(int)($x * 10)] = $x;
    }

Source: https://php.watch/versions/8.1/deprecate-implicit-conversion-incompatible-float-string#casting

Comments (6)

  1. Christian Abila reporter

    I have the solution tested and would have liked to create a pull request, but there seems to be a restriction?

  2. David Watson repo owner

    Thanks for the report Christian. This is addressed in the latest release for Moodle 4.2, which should also be compatible with Moodle 4.1. (I will mark it as compatible on moodle.org shortly)

  3. Log in to comment