Skip to content

Commit bed7139

Browse files
committed
Deprecate strptime()
Use date_parse_from_format() or IntlDateFormatter::parse() instead. Part of https://wiki.php.net/rfc/deprecations_php_8_1.
1 parent 455214d commit bed7139

File tree

7 files changed

+25
-5
lines changed

7 files changed

+25
-5
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ PHP 8.1 UPGRADE NOTES
388388
is deprecated. Instead cast the object to array first, or make use of
389389
ArrayIterator.
390390
RFC: https://wiki.php.net/rfc/deprecations_php_8_1
391+
. The strptime() function has been deprecated. Use date_parse_from_format()
392+
instead (for locale-independent parsing) or IntlDateFormatter::parse() (for
393+
locale-dependent parsing).
394+
RFC: https://wiki.php.net/rfc/deprecations_php_8_1
391395
. The FILE_BINARY and FILE_TEXT constants are deprecated. They already had
392396
no effect previously.
393397
RFC: https://wiki.php.net/rfc/deprecations_php_8_1

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ function crypt(string $string, string $salt): string {}
396396
/* datetime.c */
397397

398398
#if HAVE_STRPTIME
399+
/** @deprecated */
399400
function strptime(string $timestamp, string $format): array|false {}
400401
#endif
401402

ext/standard/basic_functions_arginfo.h

Lines changed: 2 additions & 2 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: b0a3e894735529e3fefc305cbd12f99c9b0ec3f6 */
2+
* Stub hash: aa585d759aa844227ea32a15a7382bb0f9c6b9e3 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@@ -3020,7 +3020,7 @@ static const zend_function_entry ext_functions[] = {
30203020
ZEND_FE(crc32, arginfo_crc32)
30213021
ZEND_FE(crypt, arginfo_crypt)
30223022
#if HAVE_STRPTIME
3023-
ZEND_FE(strptime, arginfo_strptime)
3023+
ZEND_DEP_FE(strptime, arginfo_strptime)
30243024
#endif
30253025
#if defined(HAVE_GETHOSTNAME)
30263026
ZEND_FE(gethostname, arginfo_gethostname)

ext/standard/tests/time/bug38524.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if (str_contains(PHP_OS, 'FreeBSD')) {
1212
var_dump(strptime('2006-08-20', '%Y-%m-%d'));
1313
?>
1414
--EXPECTF--
15+
Deprecated: Function strptime() is deprecated in %s on line %d
1516
array(9) {
1617
["tm_sec"]=>
1718
int(0)

ext/standard/tests/time/strptime_basic.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ var_dump(strptime($str, '%A %B %e %R'));
3131

3232
setlocale(LC_ALL, $orig);
3333
?>
34-
--EXPECT--
34+
--EXPECTF--
3535
*** Testing strptime() : basic functionality ***
36+
37+
Deprecated: Function strptime() is deprecated in %s on line %d
3638
array(9) {
3739
["tm_sec"]=>
3840
int(0)
@@ -53,6 +55,8 @@ array(9) {
5355
["unparsed"]=>
5456
string(4) " GMT"
5557
}
58+
59+
Deprecated: Function strptime() is deprecated in %s on line %d
5660
array(9) {
5761
["tm_sec"]=>
5862
int(0)
@@ -73,6 +77,8 @@ array(9) {
7377
["unparsed"]=>
7478
string(0) ""
7579
}
80+
81+
Deprecated: Function strptime() is deprecated in %s on line %d
7682
array(9) {
7783
["tm_sec"]=>
7884
int(0)

ext/standard/tests/time/strptime_error.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ $format = '%b %d %Y %H:%M:%S';
1818
var_dump( strptime('foo', $format) );
1919

2020
?>
21-
--EXPECT--
21+
--EXPECTF--
2222
*** Testing strptime() : error conditions ***
2323

2424
-- Testing strptime() function on failure --
25+
26+
Deprecated: Function strptime() is deprecated in %s on line %d
2527
bool(false)

ext/standard/tests/time/strptime_parts.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,26 @@ var_dump($res["tm_year"]);
4747

4848
setlocale(LC_ALL, $orig);
4949
?>
50-
--EXPECT--
50+
--EXPECTF--
5151
*** Testing strptime() : basic functionality ***
52+
53+
Deprecated: Function strptime() is deprecated in %s on line %d
5254
int(20)
5355
int(1)
5456
int(10)
5557
int(2)
5658
int(6)
5759
int(63)
60+
61+
Deprecated: Function strptime() is deprecated in %s on line %d
5862
int(20)
5963
int(1)
6064
int(10)
6165
int(2)
6266
int(6)
6367
int(163)
68+
69+
Deprecated: Function strptime() is deprecated in %s on line %d
6470
int(0)
6571
int(1)
6672
int(10)

0 commit comments

Comments
 (0)