Deprecation: #111114 - GeneralUtility::getBytesFromSizeMeasurement()
See forge#111114
Description
The method
\TYPO3\
has been marked as deprecated and will be removed in TYPO3 v16.0.
The method converted shorthand byte values such as 100k, 128M or 2G,
as used in php., into bytes. PHP provides the native function
ini_ for exactly this purpose since PHP 8.2. It
follows the same rules PHP itself applies when reading settings like
memory_, upload_ or post_, including
hexadecimal and octal notation, and returns -1 for unlimited values.
TYPO3 Core now uses the native function everywhere.
In addition, using decimal values like 1. for the options minimum and
maximum of the file size validators
\TYPO3\ and
\TYPO3\ (validator
identifier File in EXT:form) has been marked as deprecated. PHP does
not support decimal values in shorthand byte notation either.
Impact
Calling the method triggers a PHP deprecation warning. The method continues to work as before until it is removed in TYPO3 v16.0.
Configuring a file size validator with a decimal value triggers a PHP deprecation warning when the validator is executed. The value is still interpreted as before. Starting with TYPO3 v16.0, decimal values will be rejected as invalid validator options.
Affected installations
TYPO3 installations with custom extensions or code that directly call
General
are affected. The extension scanner reports any usage as a strong match.
TYPO3 installations using decimal values for the minimum or maximum
option of a file size validator, for example in Extbase
#
attributes or in EXT:form form definitions, are affected. The extension
scanner does not detect these values.
Migration
Use PHP's native function
ini_ instead.
use TYPO3\CMS\Core\Utility\GeneralUtility;
$memoryLimit = GeneralUtility::getBytesFromSizeMeasurement(ini_get('memory_limit'));
$memoryLimit = ini_parse_quantity(ini_get('memory_limit'));
Note that
ini_ emits a PHP warning for values it
cannot fully interpret, such as decimal values (1.), unknown suffixes
(100B, 1T) or values exceeding the integer range, whereas the deprecated
method silently interpreted them. Values that are not
php. settings, for example sizes entered by editors or
integrators, should be validated before they are passed to the function.
For file size validators, replace decimal values with a whole number of a
smaller unit, for example 1536K instead of 1.:
validators:
-
identifier: FileSize
options:
minimum: 0B
# Before: maximum: 1.5M
maximum: 1536K