From 7cbea84216e475ff8057a69806b0a510d218d46a Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 17 Sep 2024 15:14:07 +0200 Subject: [PATCH] PHPC-2444: Remove support for string arguments in UTCDateTime constructor --- UPGRADE-2.0.md | 3 +++ src/BSON/UTCDateTime.c | 8 +------- src/BSON/UTCDateTime.stub.php | 2 +- src/BSON/UTCDateTime_arginfo.h | 4 ++-- tests/bson/bson-utcdatetime-008.phpt | 13 ++++--------- tests/bson/bson-utcdatetime_error-003.phpt | 17 +++++------------ tests/bson/bson-utcdatetime_error-004.phpt | 4 ++-- 7 files changed, 18 insertions(+), 33 deletions(-) diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index c505fe6e9..da76671f1 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -27,3 +27,6 @@ UPGRADE FROM 1.x to 2.0 removed. Use `--with-mongodb-system-libs` instead. * All classes that previously implemented the `Serializable` interface no longer implement this interface. + * The constructor of `MongoDB\BSON\UTCDateTime` no longer accepts a `string` + argument. To pass 64-bit integers on 32-bit platforms, use the + `MongoDB\BSON\Int64` class instead. diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 568b06bdd..69299bafc 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -218,15 +218,9 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __construct) case IS_DOUBLE: php_phongo_utcdatetime_init_from_double(intern, Z_DVAL_P(milliseconds)); return; - - case IS_STRING: - php_error_docref(NULL, E_DEPRECATED, "Creating a %s instance with a string is deprecated and will be removed in ext-mongodb 2.0", ZSTR_VAL(php_phongo_utcdatetime_ce->name)); - - php_phongo_utcdatetime_init_from_string(intern, Z_STRVAL_P(milliseconds), Z_STRLEN_P(milliseconds)); - return; } - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected integer or string, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(milliseconds)); + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected integer or object, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(milliseconds)); } static PHP_METHOD(MongoDB_BSON_UTCDateTime, __set_state) diff --git a/src/BSON/UTCDateTime.stub.php b/src/BSON/UTCDateTime.stub.php index 30c201706..68104fabb 100644 --- a/src/BSON/UTCDateTime.stub.php +++ b/src/BSON/UTCDateTime.stub.php @@ -9,7 +9,7 @@ final class UTCDateTime implements UTCDateTimeInterface, \JsonSerializable, Type, \Stringable { - final public function __construct(int|string|float|\DateTimeInterface|Int64|null $milliseconds = null) {} + final public function __construct(int|float|\DateTimeInterface|Int64|null $milliseconds = null) {} final public function toDateTime(): \DateTime {} diff --git a/src/BSON/UTCDateTime_arginfo.h b/src/BSON/UTCDateTime_arginfo.h index 75a3862aa..e018df90c 100644 --- a/src/BSON/UTCDateTime_arginfo.h +++ b/src/BSON/UTCDateTime_arginfo.h @@ -1,8 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: be638e28e19d1e9c040365f20b306b82dbfadf75 */ + * Stub hash: e84944a701ed49a361960aac405d42a736037aa2 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_UTCDateTime___construct, 0, 0, 0) - ZEND_ARG_OBJ_TYPE_MASK(0, milliseconds, DateTimeInterface|MongoDB\\BSON\\Int64, MAY_BE_LONG|MAY_BE_STRING|MAY_BE_DOUBLE|MAY_BE_NULL, "null") + ZEND_ARG_OBJ_TYPE_MASK(0, milliseconds, DateTimeInterface|MongoDB\\BSON\\Int64, MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_NULL, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_UTCDateTime_toDateTime, 0, 0, DateTime, 0) diff --git a/tests/bson/bson-utcdatetime-008.phpt b/tests/bson/bson-utcdatetime-008.phpt index d39e02088..e8a9bb10f 100644 --- a/tests/bson/bson-utcdatetime-008.phpt +++ b/tests/bson/bson-utcdatetime-008.phpt @@ -5,17 +5,12 @@ MongoDB\BSON\UTCDateTime construction from 64-bit integer as string require_once __DIR__ . '/../utils/basic.inc'; -$utcdatetime = new MongoDB\BSON\UTCDateTime('1416445411987'); - -var_dump($utcdatetime); +echo throws(fn () => new MongoDB\BSON\UTCDateTime('1416445411987'), MongoDB\Driver\Exception\InvalidArgumentException::class), PHP_EOL; ?> ===DONE=== ---EXPECTF-- -Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s -object(MongoDB\BSON\UTCDateTime)#%d (%d) { - ["milliseconds"]=> - string(13) "1416445411987" -} +--EXPECT-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected integer or object, string given ===DONE=== diff --git a/tests/bson/bson-utcdatetime_error-003.phpt b/tests/bson/bson-utcdatetime_error-003.phpt index 6eb1fa741..3b5afdcf3 100644 --- a/tests/bson/bson-utcdatetime_error-003.phpt +++ b/tests/bson/bson-utcdatetime_error-003.phpt @@ -26,20 +26,13 @@ echo throws(function() { ?> ===DONE=== ---EXPECTF-- -Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s +--EXPECT-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Error parsing "1234.5678" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization - -Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s +Expected integer or object, string given OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Error parsing "9223372036854775808" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization - -Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s +Expected integer or object, string given OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Error parsing "-9223372036854775809" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization - -Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s +Expected integer or object, string given OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Error parsing "18446744073709551615" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization +Expected integer or object, string given ===DONE=== diff --git a/tests/bson/bson-utcdatetime_error-004.phpt b/tests/bson/bson-utcdatetime_error-004.phpt index 3ac92dea1..e4d123a43 100644 --- a/tests/bson/bson-utcdatetime_error-004.phpt +++ b/tests/bson/bson-utcdatetime_error-004.phpt @@ -21,7 +21,7 @@ foreach ($invalidValues as $invalidValue) { --EXPECT-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected integer or string, bool given +Expected integer or object, bool given OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected integer or string, array given +Expected integer or object, array given ===DONE===