Skip to content

Commit

Permalink
Deprecate strftime() and gmstrftime()
Browse files Browse the repository at this point in the history
These are deprecated in favor of date()/DateTime::format() (for
locale-indendent formatting) and IntlDateFormatter::format()
(for locale-dependent formatting).

Part of https://wiki.php.net/rfc/deprecations_php_8_1.
  • Loading branch information
nikic committed Jul 14, 2021
1 parent 9491694 commit 4b3615a
Show file tree
Hide file tree
Showing 53 changed files with 483 additions and 34 deletions.
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ PHP 8.1 UPGRADE NOTES
. The date_sunrise() and date_sunset() functions have been deprecated in
favor of date_sun_info().
RFC: https://wiki.php.net/rfc/deprecations_php_8_1
. 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).

- Filter:
. The FILTER_SANITIZE_STRING and FILTER_SANITIZE_STRIPPED filters have been
Expand Down
2 changes: 2 additions & 0 deletions ext/date/php_date.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ function gmmktime(

function checkdate(int $month, int $day, int $year): bool {}

/** @deprecated */
function strftime(string $format, ?int $timestamp = null): string|false {}

/** @deprecated */
function gmstrftime(string $format, ?int $timestamp = null): string|false {}

function time(): int {}
Expand Down
6 changes: 3 additions & 3 deletions ext/date/php_date_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: fbec11a67d5cc04667a012f25894f0d9e18833a6 */
* Stub hash: bc0634c149cda640616f7ecd7e173a0d6497a911 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0)
Expand Down Expand Up @@ -559,8 +559,8 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(mktime, arginfo_mktime)
ZEND_FE(gmmktime, arginfo_gmmktime)
ZEND_FE(checkdate, arginfo_checkdate)
ZEND_FE(strftime, arginfo_strftime)
ZEND_FE(gmstrftime, arginfo_gmstrftime)
ZEND_DEP_FE(strftime, arginfo_strftime)
ZEND_DEP_FE(gmstrftime, arginfo_gmstrftime)
ZEND_FE(time, arginfo_time)
ZEND_FE(localtime, arginfo_localtime)
ZEND_FE(getdate, arginfo_getdate)
Expand Down
15 changes: 15 additions & 0 deletions ext/date/tests/009.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,29 @@ var_dump(gmstrftime("blah", $t));
echo "Done\n";
?>
--EXPECTF--
Deprecated: Function strftime() is deprecated in %s on line %d
bool(false)

Deprecated: Function strftime() is deprecated in %s on line %d
string(%d) "Tue Tuesday Jun June Tue Jun 27 00:00:00 2006 %s
%s %"

Deprecated: Function strftime() is deprecated in %s on line %d
string(5) "%q %a"

Deprecated: Function strftime() is deprecated in %s on line %d
string(4) "blah"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
bool(false)

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "Mon Monday Jun June Mon Jun 26 21:00:00 2006 %s
%s %"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(5) "%q %a"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(4) "blah"
Done
15 changes: 15 additions & 0 deletions ext/date/tests/009_win32.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,27 @@ echo "Done\n";
setlocale(LC_TIME, $loc);
?>
--EXPECTF--
Deprecated: Function strftime() is deprecated in %s on line %d
bool(false)

Deprecated: Function strftime() is deprecated in %s on line %d
string(%d) "Tue Tuesday Jun June 6/27/2006 12:00:00 AM 27 00 12 178 06 00 AM 00 26 26 2 6/27/2006 12:00:00 AM 06 2006 %s"

Deprecated: Function strftime() is deprecated in %s on line %d
string(5) "%q %a"

Deprecated: Function strftime() is deprecated in %s on line %d
string(4) "blah"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
bool(false)

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "Mon Monday Jun June 6/26/2006 9:00:00 PM 26 21 09 177 06 00 PM 00 26 26 1 6/26/2006 9:00:00 PM 06 2006 %s"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(5) "%q %a"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(4) "blah"
Done
2 changes: 1 addition & 1 deletion ext/date/tests/bug33532.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ date.timezone=UTC
--SKIPIF--
<?php
if(PHP_OS == 'Darwin' || defined('PHP_WINDOWS_VERSION_MAJOR')) die("skip strftime uses system TZ on Darwin and Windows");
if (!strftime('%Z')) die('skip strftime does not support %Z');
if (!@strftime('%Z')) die('skip strftime does not support %Z');
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/date/tests/bug65184.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
?>
--INI--
date.timezone = UTC
error_reporting=E_ALL&~E_DEPRECATED
--FILE--
<?php
setlocale(LC_ALL, 'Japanese_Japan.932');
Expand Down
6 changes: 5 additions & 1 deletion ext/date/tests/bug65371.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ function p($str)
setlocale(LC_ALL, 'C');
p('あ');
?>
--EXPECT--
--EXPECTF--

Deprecated: Function strftime() is deprecated in %s on line %d
e38182

Deprecated: Function strftime() is deprecated in %s on line %d
e38182
4 changes: 4 additions & 0 deletions ext/date/tests/gmstrftime_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ var_dump( gmstrftime($format) );
?>
--EXPECTF--
*** Testing gmstrftime() : basic functionality ***

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(20) "Aug 08 2008 08:08:08"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%s %d %d %d:%d:%d"
8 changes: 8 additions & 0 deletions ext/date/tests/gmstrftime_variation10.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ foreach($inputs as $key =>$value) {
*** Testing gmstrftime() : usage variation ***

--The ISO 8601:1988 week number--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) "32"

--Weekday as decimal--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(1) "5"
4 changes: 4 additions & 0 deletions ext/date/tests/gmstrftime_variation11.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ var_dump( gmstrftime($format, $timestamp) );
*** Testing gmstrftime() : usage variation ***

-- Testing gmstrftime() function with Abbreviated month name format %h --

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%s"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(3) "Aug"
4 changes: 4 additions & 0 deletions ext/date/tests/gmstrftime_variation12.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ var_dump( gmstrftime($format, $timestamp) );
*** Testing gmstrftime() : usage variation ***

-- Testing gmstrftime() function with Abbreviated month name format %h --

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%s"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(3) "Aug"
16 changes: 16 additions & 0 deletions ext/date/tests/gmstrftime_variation13.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,33 @@ foreach($inputs as $key =>$value) {
*** Testing gmstrftime() : usage variation ***

--Century number--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) "%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) "20"

--Month Date Year--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d/%d/%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(8) "08/08/08"

--Year with century--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(4) "2008"

--Year without century--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) "%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) "08"
16 changes: 16 additions & 0 deletions ext/date/tests/gmstrftime_variation14.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,33 @@ foreach($inputs as $key =>$value) {
*** Testing gmstrftime() : usage variation ***

--Century number--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) "20"

--Month Date Year--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d/%d/%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(8) "08/08/08"

--Year with century--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(4) "2008"

--Year without century--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) "08"
12 changes: 12 additions & 0 deletions ext/date/tests/gmstrftime_variation15.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ foreach($inputs as $key =>$value) {
*** Testing gmstrftime() : usage variation ***

--Time in a.m/p.m notation--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d:%d:%d %c%c"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(11) "08:08:08 AM"

--Time in 24 hour notation--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d:%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(5) "08:08"

--Current time %H:%M:%S format--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d:%d:%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(8) "08:08:08"
12 changes: 12 additions & 0 deletions ext/date/tests/gmstrftime_variation16.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,25 @@ foreach($inputs as $key =>$value) {
*** Testing gmstrftime() : usage variation ***

--Time in a.m/p.m notation--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d:%d:%d %s"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(11) "02:08:08 PM"

--Time in 24 hour notation--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d:%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(5) "14:08"

--Current time %H:%M:%S format--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d:%d:%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(8) "14:08:08"
4 changes: 4 additions & 0 deletions ext/date/tests/gmstrftime_variation17.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ var_dump( gmstrftime($format, $timestamp) );
*** Testing gmstrftime() : usage variation ***

-- Testing gmstrftime() function with Day of the month as decimal single digit format --

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) "%A%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) " 8"
4 changes: 4 additions & 0 deletions ext/date/tests/gmstrftime_variation18.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ var_dump( gmstrftime($format, $timestamp) );
*** Testing gmstrftime() : usage variation ***

-- Testing gmstrftime() function with Day of the month as decimal single digit format --

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%s"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(2) " 8"
10 changes: 9 additions & 1 deletion ext/date/tests/gmstrftime_variation19.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ foreach($inputs as $key =>$value) {
};

?>
--EXPECT--
--EXPECTF--
*** Testing gmstrftime() : usage variation ***

--Newline character--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(1) "
"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(1) "
"

--Tab character--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(1) " "

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(1) " "
20 changes: 14 additions & 6 deletions ext/date/tests/gmstrftime_variation20.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,23 @@ foreach($inputs as $key =>$value) {
};

?>
--EXPECTREGEX--
\*\*\* Testing gmstrftime\(\) : usage variation \*\*\*
--EXPECTF--
*** Testing gmstrftime() : usage variation ***

--Newline character--
string\(1\) "

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(1) "
"
string\(1\) "

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(1) "
"

--Tab character--
string\(1\) "\s"
string\(1\) "\s"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(1) "%r\s%r"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(1) "%r\s%r"
12 changes: 12 additions & 0 deletions ext/date/tests/gmstrftime_variation21.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ foreach($inputs as $key =>$value) {
*** Testing gmstrftime() : usage variation ***

--Preferred date and time representation--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%s %s %d %d:%d:%d %d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(24) "Fri Aug 8 08:08:08 2008"

--Preferred date representation--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d/%d/%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(8) "08/08/08"

--Preferred time representation--

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(%d) "%d:%d:%d"

Deprecated: Function gmstrftime() is deprecated in %s on line %d
string(8) "08:08:08"

0 comments on commit 4b3615a

Please sign in to comment.