Skip to content

Commit 4b3615a

Browse files
committed
Deprecate strftime() and gmstrftime()
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.
1 parent 9491694 commit 4b3615a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+483
-34
lines changed

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ PHP 8.1 UPGRADE NOTES
359359
. The date_sunrise() and date_sunset() functions have been deprecated in
360360
favor of date_sun_info().
361361
RFC: https://wiki.php.net/rfc/deprecations_php_8_1
362+
. The strftime() and gmstrftime() functions have been deprecated in favor of
363+
date()/DateTime::format() (for locale-independent formatting) or
364+
IntlDateFormatter::format() (for locale-dependent formatting).
362365

363366
- Filter:
364367
. The FILTER_SANITIZE_STRING and FILTER_SANITIZE_STRIPPED filters have been

ext/date/php_date.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ function gmmktime(
2020

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

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

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

2729
function time(): int {}

ext/date/php_date_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: fbec11a67d5cc04667a012f25894f0d9e18833a6 */
2+
* Stub hash: bc0634c149cda640616f7ecd7e173a0d6497a911 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0)
@@ -559,8 +559,8 @@ static const zend_function_entry ext_functions[] = {
559559
ZEND_FE(mktime, arginfo_mktime)
560560
ZEND_FE(gmmktime, arginfo_gmmktime)
561561
ZEND_FE(checkdate, arginfo_checkdate)
562-
ZEND_FE(strftime, arginfo_strftime)
563-
ZEND_FE(gmstrftime, arginfo_gmstrftime)
562+
ZEND_DEP_FE(strftime, arginfo_strftime)
563+
ZEND_DEP_FE(gmstrftime, arginfo_gmstrftime)
564564
ZEND_FE(time, arginfo_time)
565565
ZEND_FE(localtime, arginfo_localtime)
566566
ZEND_FE(getdate, arginfo_getdate)

ext/date/tests/009.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,29 @@ var_dump(gmstrftime("blah", $t));
2323
echo "Done\n";
2424
?>
2525
--EXPECTF--
26+
Deprecated: Function strftime() is deprecated in %s on line %d
2627
bool(false)
28+
29+
Deprecated: Function strftime() is deprecated in %s on line %d
2730
string(%d) "Tue Tuesday Jun June Tue Jun 27 00:00:00 2006 %s
2831
%s %"
32+
33+
Deprecated: Function strftime() is deprecated in %s on line %d
2934
string(5) "%q %a"
35+
36+
Deprecated: Function strftime() is deprecated in %s on line %d
3037
string(4) "blah"
38+
39+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
3140
bool(false)
41+
42+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
3243
string(%d) "Mon Monday Jun June Mon Jun 26 21:00:00 2006 %s
3344
%s %"
45+
46+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
3447
string(5) "%q %a"
48+
49+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
3550
string(4) "blah"
3651
Done

ext/date/tests/009_win32.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,27 @@ echo "Done\n";
3535
setlocale(LC_TIME, $loc);
3636
?>
3737
--EXPECTF--
38+
Deprecated: Function strftime() is deprecated in %s on line %d
3839
bool(false)
40+
41+
Deprecated: Function strftime() is deprecated in %s on line %d
3942
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"
43+
44+
Deprecated: Function strftime() is deprecated in %s on line %d
4045
string(5) "%q %a"
46+
47+
Deprecated: Function strftime() is deprecated in %s on line %d
4148
string(4) "blah"
49+
50+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
4251
bool(false)
52+
53+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
4354
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"
55+
56+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
4457
string(5) "%q %a"
58+
59+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
4560
string(4) "blah"
4661
Done

ext/date/tests/bug33532.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ date.timezone=UTC
66
--SKIPIF--
77
<?php
88
if(PHP_OS == 'Darwin' || defined('PHP_WINDOWS_VERSION_MAJOR')) die("skip strftime uses system TZ on Darwin and Windows");
9-
if (!strftime('%Z')) die('skip strftime does not support %Z');
9+
if (!@strftime('%Z')) die('skip strftime does not support %Z');
1010
?>
1111
--FILE--
1212
<?php

ext/date/tests/bug65184.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
88
?>
99
--INI--
1010
date.timezone = UTC
11+
error_reporting=E_ALL&~E_DEPRECATED
1112
--FILE--
1213
<?php
1314
setlocale(LC_ALL, 'Japanese_Japan.932');

ext/date/tests/bug65371.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ function p($str)
1616
setlocale(LC_ALL, 'C');
1717
p('');
1818
?>
19-
--EXPECT--
19+
--EXPECTF--
2020
21+
22+
Deprecated: Function strftime() is deprecated in %s on line %d
2123
2224
e38182
25+
26+
Deprecated: Function strftime() is deprecated in %s on line %d
2327
e38182

ext/date/tests/gmstrftime_basic.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ var_dump( gmstrftime($format) );
1717
?>
1818
--EXPECTF--
1919
*** Testing gmstrftime() : basic functionality ***
20+
21+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
2022
string(20) "Aug 08 2008 08:08:08"
23+
24+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
2125
string(%d) "%s %d %d %d:%d:%d"

ext/date/tests/gmstrftime_variation10.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@ foreach($inputs as $key =>$value) {
3434
*** Testing gmstrftime() : usage variation ***
3535

3636
--The ISO 8601:1988 week number--
37+
38+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
3739
string(%d) "%d"
40+
41+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
3842
string(2) "32"
3943

4044
--Weekday as decimal--
45+
46+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
4147
string(%d) "%d"
48+
49+
Deprecated: Function gmstrftime() is deprecated in %s on line %d
4250
string(1) "5"

0 commit comments

Comments
 (0)