[wp-trac] [WordPress Trac] #53897: PHP 8.1: strftime() is deprecated
WordPress Trac
noreply at wordpress.org
Mon Aug 9 02:28:05 UTC 2021
#53897: PHP 8.1: strftime() is deprecated
------------------------------+-----------------------------------
Reporter: jrf | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.9
Component: Build/Test Tools | Version:
Severity: normal | Keywords: has-patch early php81
Focuses: |
------------------------------+-----------------------------------
> The `strftime()` and `gmstrftime()` functions exhibit similar issues as
`strptime()`, in that the formats they support, as well as their behavior,
is platform-dependent. Unlike `strptime()`, these functions are available
on Windows, though with a different feature set than on Linux. Musl-based
distributions like Alpine do not support timezone-related format
specifiers correctly. These functions are also locale-based, and as such
may exhibit thread-safety issues.
>
> `date()` or `DateTime::format()` provide portable alternatives, and
`IntlDateFormatter::format()` provides a more sophisticated, localization-
aware alternative.
Ref: https://wiki.php.net/rfc/deprecations_php_8_1#strftime_and_gmstrftime
> The `strftime()` and `gmstrftime()` functions have been deprecated in
favor of
> `date()/DateTime::format()` (for locale-independent formatting) or
> `IntlDateFormatter::format()` (for locale-dependent formatting).
Ref: https://github.com/php/php-
src/blob/1cf4fb739f7a4fa8404a4c0958f13d04eae519d4/UPGRADING#L379-L381
Aside from one instance in SimplePie, the `strftime()` function is only
used within the test suite of WordPress to create formatted timestamps.
As the function is used in test code, this leads to test output like this
on PHP 8.1:
{{{
........................................................... 767 / 12462
( 6%)
............
Deprecated: Function strftime() is deprecated in
path/to/tests/phpunit/tests/canonical/postStatus.php on line 37
............................................... 826 / 12462 ( 6%)
}}}
It also is the cause of 17 tests erroring out on PHP 8.1.
These calls can all be safely converted to use a pattern along the lines
of:
{{{#!php
<?php
date_format( date_create( 'time phrase or timestamp' ), $format )
}}}
Verification of the principle:
https://3v4l.org/MCURg
Other references:
* https://www.php.net/manual/en/function.strftime.php (for the old format
string characters)
* https://www.php.net/manual/en/datetime.format.php (for the new format
string characters)
* https://www.php.net/manual/en/datetime.construct.php (see Example 2 for
a Unix timestamp code sample)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53897>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list