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 deleted file mode 100644 index d39e02088..000000000 --- a/tests/bson/bson-utcdatetime-008.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -MongoDB\BSON\UTCDateTime construction from 64-bit integer as string ---FILE-- - -===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" -} -===DONE=== diff --git a/tests/bson/bson-utcdatetime_error-003.phpt b/tests/bson/bson-utcdatetime_error-003.phpt deleted file mode 100644 index 6eb1fa741..000000000 --- a/tests/bson/bson-utcdatetime_error-003.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -MongoDB\BSON\UTCDateTime constructor requires strings to parse as 64-bit integers ---FILE-- - -===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 -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 -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 -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 -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Error parsing "18446744073709551615" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization -===DONE=== diff --git a/tests/bson/bson-utcdatetime_error-004.phpt b/tests/bson/bson-utcdatetime_error-004.phpt index 3ac92dea1..9e8798050 100644 --- a/tests/bson/bson-utcdatetime_error-004.phpt +++ b/tests/bson/bson-utcdatetime_error-004.phpt @@ -8,12 +8,19 @@ require_once __DIR__ . '/../utils/basic.inc'; /* UTCDateTime::__construct() internally converts floats to integers, so we will * not use a float to test for an invalid value. We also don't test an object, * since that is used for validating a possible DateTimeInterface argument. */ -$invalidValues = [true, []]; +$invalidValues = [ + true, + [], + // Numeric strings are no longer supported as of 2.0 + '1416445411987', + '1234.5678', +]; foreach ($invalidValues as $invalidValue) { - echo throws(function() use ($invalidValue) { - new MongoDB\BSON\UTCDateTime($invalidValue); - }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; + echo throws( + fn () => new MongoDB\BSON\UTCDateTime($invalidValue), + MongoDB\Driver\Exception\InvalidArgumentException::class, + ), PHP_EOL; } ?> @@ -21,7 +28,11 @@ 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 +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected integer or object, string given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected integer or object, string given ===DONE===