WordPress.org

Make WordPress Core

Changeset 51636


Ignore:
Timestamp:
08/18/2021 09:57:21 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Silence the deprecation warning for auto_detect_line_endings.

Since PHP 8.1, the auto_detect_line_endings setting is deprecated:

The auto_detect_line_endings ini setting modifies the behavior of file() and fgets() to support an isolated \r (as opposed to \n or \r\n) as a newline character. These newlines were used by “Classic” Mac OS, a system which has been discontinued in 2001, nearly two decades ago. Interoperability with such systems is no longer relevant.

Reference: PHP RFC: Deprecations for PHP 8.1: auto_detect_line_endings ini setting

The auto_detect_line_endings ini setting has been deprecated. If necessary, handle \r line breaks manually instead.

Reference: PHP 8.1 Upgrade Notes.

This commit fixes the warning when running tests for the PO class:

Deprecated: auto_detect_line_endings is deprecated in /var/www/src/wp-includes/pomo/po.php on line 16

While deprecated, the actual auto_detect_line_endings functionality has not been removed from PHP (yet) and will still work until PHP 9.0.

For now, we're silencing the deprecation notice as there may still be translation files around which haven't been updated in a long time and which still use the old MacOS standalone \r as a line ending.

This should be revisited when PHP 9.0 is in alpha/beta.

Follow-up to [51633].

Props jrf.
See #53635.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pomo/po.php

    r51633 r51636  
    1414}
    1515
    16 // This setting has been deprecated in PHP 8.1.
    17 if ( PHP_VERSION_ID < 80100 ) {
    18     ini_set( 'auto_detect_line_endings', 1 );
    19 }
     16/*
     17 * The `auto_detect_line_endings` setting has been deprecated in PHP 8.1,
     18 * but will continue to work until PHP 9.0.
     19 * For now, we're silencing the deprecation notice as there may still be
     20 * translation files around which haven't been updated in a long time and
     21 * which still use the old MacOS standalone `\r` as a line ending.
     22 * This fix should be revisited when PHP 9.0 is in alpha/beta.
     23 */
     24@ini_set( 'auto_detect_line_endings', 1 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
    2025
    2126/**
Note: See TracChangeset for help on using the changeset viewer.