Skip to content

Commit 5d8643a

Browse files
committed
PHPC-2444: Remove support for string arguments in UTCDateTime constructor
1 parent ca52367 commit 5d8643a

File tree

7 files changed

+18
-33
lines changed

7 files changed

+18
-33
lines changed

UPGRADE-2.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ UPGRADE FROM 1.x to 2.0
44
* The `getServer()` method has been removed from the CommandFailedEvent,
55
CommandStartedEvent, and CommandSucceededEvent event classes. The `getHost()`
66
and `getPort()` methods have been added in its place.
7+
* The constructor of `MongoDB\BSON\UTCDateTime` no longer accepts a `string`
8+
argument. To pass 64-bit integers on 32-bit platforms, use the
9+
`MongoDB\BSON\Int64` class instead.

src/BSON/UTCDateTime.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,9 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __construct)
220220
case IS_DOUBLE:
221221
php_phongo_utcdatetime_init_from_double(intern, Z_DVAL_P(milliseconds));
222222
return;
223-
224-
case IS_STRING:
225-
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));
226-
227-
php_phongo_utcdatetime_init_from_string(intern, Z_STRVAL_P(milliseconds), Z_STRLEN_P(milliseconds));
228-
return;
229223
}
230224

231-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected integer or string, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(milliseconds));
225+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected integer or object, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(milliseconds));
232226
}
233227

234228
static PHP_METHOD(MongoDB_BSON_UTCDateTime, __set_state)

src/BSON/UTCDateTime.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
final class UTCDateTime implements UTCDateTimeInterface, \JsonSerializable, Type, \Serializable, \Stringable
1111
{
12-
final public function __construct(int|string|float|\DateTimeInterface|Int64|null $milliseconds = null) {}
12+
final public function __construct(int|float|\DateTimeInterface|Int64|null $milliseconds = null) {}
1313

1414
final public function toDateTime(): \DateTime {}
1515

src/BSON/UTCDateTime_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/bson/bson-utcdatetime-008.phpt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@ MongoDB\BSON\UTCDateTime construction from 64-bit integer as string
55

66
require_once __DIR__ . '/../utils/basic.inc';
77

8-
$utcdatetime = new MongoDB\BSON\UTCDateTime('1416445411987');
9-
10-
var_dump($utcdatetime);
8+
echo throws(fn () => new MongoDB\BSON\UTCDateTime('1416445411987'), MongoDB\Driver\Exception\InvalidArgumentException::class), PHP_EOL;
119

1210
?>
1311
===DONE===
1412
<?php exit(0); ?>
15-
--EXPECTF--
16-
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
17-
object(MongoDB\BSON\UTCDateTime)#%d (%d) {
18-
["milliseconds"]=>
19-
string(13) "1416445411987"
20-
}
13+
--EXPECT--
14+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
15+
Expected integer or object, string given
2116
===DONE===

tests/bson/bson-utcdatetime_error-003.phpt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,13 @@ echo throws(function() {
2626
?>
2727
===DONE===
2828
<?php exit(0); ?>
29-
--EXPECTF--
30-
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
29+
--EXPECT--
3130
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
32-
Error parsing "1234.5678" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
33-
34-
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
31+
Expected integer or object, string given
3532
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
36-
Error parsing "9223372036854775808" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
37-
38-
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
33+
Expected integer or object, string given
3934
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
40-
Error parsing "-9223372036854775809" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
41-
42-
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
35+
Expected integer or object, string given
4336
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
44-
Error parsing "18446744073709551615" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
37+
Expected integer or object, string given
4538
===DONE===

tests/bson/bson-utcdatetime_error-004.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ foreach ($invalidValues as $invalidValue) {
2121
<?php exit(0); ?>
2222
--EXPECT--
2323
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
24-
Expected integer or string, bool given
24+
Expected integer or object, bool given
2525
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
26-
Expected integer or string, array given
26+
Expected integer or object, array given
2727
===DONE===

0 commit comments

Comments
 (0)