Deprecate strptime()

Use date_parse_from_format() or IntlDateFormatter::parse() instead.

Part of https://wiki.php.net/rfc/deprecations_php_8_1.
This commit is contained in:
Nikita Popov 2021-07-08 16:30:52 +02:00
parent 455214d6f0
commit bed7139375
7 changed files with 25 additions and 5 deletions

View File

@ -388,6 +388,10 @@ PHP 8.1 UPGRADE NOTES
is deprecated. Instead cast the object to array first, or make use of
ArrayIterator.
RFC: https://wiki.php.net/rfc/deprecations_php_8_1
. The strptime() function has been deprecated. Use date_parse_from_format()
instead (for locale-independent parsing) or IntlDateFormatter::parse() (for
locale-dependent parsing).
RFC: https://wiki.php.net/rfc/deprecations_php_8_1
. The FILE_BINARY and FILE_TEXT constants are deprecated. They already had
no effect previously.
RFC: https://wiki.php.net/rfc/deprecations_php_8_1

View File

@ -396,6 +396,7 @@ function crypt(string $string, string $salt): string {}
/* datetime.c */
#if HAVE_STRPTIME
/** @deprecated */
function strptime(string $timestamp, string $format): array|false {}
#endif

View File

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: b0a3e894735529e3fefc305cbd12f99c9b0ec3f6 */
* Stub hash: aa585d759aa844227ea32a15a7382bb0f9c6b9e3 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@ -3020,7 +3020,7 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(crc32, arginfo_crc32)
ZEND_FE(crypt, arginfo_crypt)
#if HAVE_STRPTIME
ZEND_FE(strptime, arginfo_strptime)
ZEND_DEP_FE(strptime, arginfo_strptime)
#endif
#if defined(HAVE_GETHOSTNAME)
ZEND_FE(gethostname, arginfo_gethostname)

View File

@ -12,6 +12,7 @@ if (str_contains(PHP_OS, 'FreeBSD')) {
var_dump(strptime('2006-08-20', '%Y-%m-%d'));
?>
--EXPECTF--
Deprecated: Function strptime() is deprecated in %s on line %d
array(9) {
["tm_sec"]=>
int(0)

View File

@ -31,8 +31,10 @@ var_dump(strptime($str, '%A %B %e %R'));
setlocale(LC_ALL, $orig);
?>
--EXPECT--
--EXPECTF--
*** Testing strptime() : basic functionality ***
Deprecated: Function strptime() is deprecated in %s on line %d
array(9) {
["tm_sec"]=>
int(0)
@ -53,6 +55,8 @@ array(9) {
["unparsed"]=>
string(4) " GMT"
}
Deprecated: Function strptime() is deprecated in %s on line %d
array(9) {
["tm_sec"]=>
int(0)
@ -73,6 +77,8 @@ array(9) {
["unparsed"]=>
string(0) ""
}
Deprecated: Function strptime() is deprecated in %s on line %d
array(9) {
["tm_sec"]=>
int(0)

View File

@ -18,8 +18,10 @@ $format = '%b %d %Y %H:%M:%S';
var_dump( strptime('foo', $format) );
?>
--EXPECT--
--EXPECTF--
*** Testing strptime() : error conditions ***
-- Testing strptime() function on failure --
Deprecated: Function strptime() is deprecated in %s on line %d
bool(false)

View File

@ -47,20 +47,26 @@ var_dump($res["tm_year"]);
setlocale(LC_ALL, $orig);
?>
--EXPECT--
--EXPECTF--
*** Testing strptime() : basic functionality ***
Deprecated: Function strptime() is deprecated in %s on line %d
int(20)
int(1)
int(10)
int(2)
int(6)
int(63)
Deprecated: Function strptime() is deprecated in %s on line %d
int(20)
int(1)
int(10)
int(2)
int(6)
int(163)
Deprecated: Function strptime() is deprecated in %s on line %d
int(0)
int(1)
int(10)