Passing null to parameter #1 ($num) of type int|float to abs() is deprecated

Created on 28 January 2022, almost 3 years ago
Updated 22 July 2023, over 1 year ago

Problem/Motivation

The file_managed.filesize column could be null, if the file size couldn't be determined. So we need to check that the file size is not null before passing to format_size(), which expects an integer.

The PHP 8.1 error messages are: Deprecated function: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in format_size() (line 138 of core/includes/common.inc) and Deprecated function: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Html::escape() (line 424 of core/lib/Drupal/Component/Utility/Html.php) - there are two deprecations because the null size is also passed thru htmlspecialchars() as the @count placeholder. (Hmm, having strict type checking someday in format_size() would prevent the need to pass the number thru htmlspecialchars() :)

Steps to reproduce

Create a File entity with null size (e.g. file doesn't exist or can't be statted), and use it with the table of files field formatter.

Proposed resolution

  • Chosen resolution: Patch #37: File table field formatter outputs t('Unknown') if size is NULL; file link outputs empty string if size is NULL

Remaining tasks

Review patch.

🐛 Bug report
Status

Fixed

Version

10.1

Component
File system 

Last updated about 11 hours ago

Created by

🇺🇸United States mfb San Francisco

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024