Skip to content

Commit 979cb4b

Browse files
authored
PHPC-2459: Remove support for float arg in UTCDateTime ctor (#1709)
This also folds bson-utcdatetime_error-001.phpt into bson-utcdatetime_error-004.phpt.
1 parent e8cc2e5 commit 979cb4b

File tree

7 files changed

+14
-80
lines changed

7 files changed

+14
-80
lines changed

UPGRADE-2.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ UPGRADE FROM 1.x to 2.0
2727
removed. Use `--with-mongodb-system-libs` instead.
2828
* All classes that previously implemented the `Serializable` interface no
2929
longer implement this interface.
30-
* The constructor of `MongoDB\BSON\UTCDateTime` no longer accepts a `string`
31-
argument. To pass 64-bit integers on 32-bit platforms, use the
30+
* The constructor of `MongoDB\BSON\UTCDateTime` no longer accepts a `string` or
31+
`float` argument. To pass 64-bit integers on 32-bit platforms, use the
3232
`MongoDB\BSON\Int64` class instead.
3333
* The `--with-openssl-dir` configure option has been removed. If using OpenSSL,
3434
ensure that it is detected by `pkg-config`.

src/BSON/UTCDateTime.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,6 @@ static bool php_phongo_utcdatetime_init_from_object(php_phongo_utcdatetime_t* in
121121
return false;
122122
}
123123

124-
static bool php_phongo_utcdatetime_init_from_double(php_phongo_utcdatetime_t* intern, double milliseconds)
125-
{
126-
char tmp[24];
127-
int tmp_len;
128-
129-
tmp_len = snprintf(tmp, sizeof(tmp), "%.0f", milliseconds > 0 ? floor(milliseconds) : ceil(milliseconds));
130-
131-
return php_phongo_utcdatetime_init_from_string(intern, tmp, tmp_len);
132-
}
133-
134124
static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object, bool is_temp)
135125
{
136126
php_phongo_utcdatetime_t* intern;
@@ -214,12 +204,6 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __construct)
214204
case IS_LONG:
215205
php_phongo_utcdatetime_init(intern, Z_LVAL_P(milliseconds));
216206
return;
217-
218-
case IS_DOUBLE:
219-
php_error_docref(NULL, E_DEPRECATED, "Creating a %s instance with a float is deprecated and will be removed in ext-mongodb 2.0", ZSTR_VAL(php_phongo_utcdatetime_ce->name));
220-
221-
php_phongo_utcdatetime_init_from_double(intern, Z_DVAL_P(milliseconds));
222-
return;
223207
}
224208

225209
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected integer or object, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(milliseconds));

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, \Stringable
1111
{
12-
final public function __construct(int|float|\DateTimeInterface|Int64|null $milliseconds = null) {}
12+
final public function __construct(int|\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-007.phpt

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/bson/bson-utcdatetime_error-001.phpt

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/bson/bson-utcdatetime_error-004.phpt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
--TEST--
2-
MongoDB\BSON\UTCDateTime constructor requires integer or string argument
2+
MongoDB\BSON\UTCDateTime constructor type validation
33
--FILE--
44
<?php
55

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

8-
/* UTCDateTime::__construct() internally converts floats to integers, so we will
9-
* not use a float to test for an invalid value. We also don't test an object,
10-
* since that is used for validating a possible DateTimeInterface argument. */
118
$invalidValues = [
129
true,
1310
[],
1411
// Numeric strings are no longer supported as of 2.0
1512
'1416445411987',
1613
'1234.5678',
14+
// Floats are no longer supported as of 2.0
15+
1234.5678,
16+
// Only DateTimeInterface or MongoDB\BSON\Int64 is accepted
17+
new stdClass,
1718
];
1819

1920
foreach ($invalidValues as $invalidValue) {
@@ -35,4 +36,8 @@ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
3536
Expected integer or object, string given
3637
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
3738
Expected integer or object, string given
39+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
40+
Expected integer or object, float given
41+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
42+
Expected instance of DateTimeInterface or MongoDB\BSON\Int64, stdClass given
3843
===DONE===

0 commit comments

Comments
 (0)