Skip to content

Commit 9b9f774

Browse files
authored
PHPC-2458: Deprecate float arg for UTCDateTime constructor (#1695)
1 parent 25de213 commit 9b9f774

9 files changed

+14
-7
lines changed

src/BSON/UTCDateTime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __construct)
218218
return;
219219

220220
case IS_DOUBLE:
221+
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));
222+
221223
php_phongo_utcdatetime_init_from_double(intern, Z_DVAL_P(milliseconds));
222224
return;
223225

tests/bson/bson-document-toCanonicalJSON-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc';
88
$tests = [
99
[ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ],
1010
[ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ],
11-
[ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ],
11+
[ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ],
1212
[ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ],
1313
[ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ],
1414
[ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ],

tests/bson/bson-document-toRelaxedJSON-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc';
88
$tests = [
99
[ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ],
1010
[ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ],
11-
[ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ],
11+
[ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ],
1212
[ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ],
1313
[ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ],
1414
[ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ],

tests/bson/bson-packedarray-toCanonicalJSON-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc';
88
$tests = [
99
[new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ],
1010
[new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ],
11-
[new MongoDB\BSON\UTCDateTime(1445990400000) ],
11+
[new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ],
1212
[new MongoDB\BSON\Timestamp(1234, 5678) ],
1313
[new MongoDB\BSON\Regex('pattern', 'i') ],
1414
[new MongoDB\BSON\Javascript('function() { return 1; }') ],

tests/bson/bson-packedarray-toRelaxedExtendedJSON-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc';
88
$tests = [
99
[ new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ],
1010
[ new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ],
11-
[ new MongoDB\BSON\UTCDateTime(1445990400000) ],
11+
[ new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ],
1212
[ new MongoDB\BSON\Timestamp(1234, 5678) ],
1313
[ new MongoDB\BSON\Regex('pattern', 'i') ],
1414
[ new MongoDB\BSON\Javascript('function() { return 1; }') ],

tests/bson/bson-toCanonicalJSON-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc';
88
$tests = [
99
[ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ],
1010
[ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ],
11-
[ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ],
11+
[ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ],
1212
[ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ],
1313
[ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ],
1414
[ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ],

tests/bson/bson-toJSON-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc';
88
$tests = [
99
[ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ],
1010
[ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ],
11-
[ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ],
11+
[ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ],
1212
[ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ],
1313
[ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ],
1414
[ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ],

tests/bson/bson-toRelaxedJSON-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc';
88
$tests = [
99
[ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ],
1010
[ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ],
11-
[ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ],
11+
[ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ],
1212
[ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ],
1313
[ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ],
1414
[ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ],

tests/bson/bson-utcdatetime-007.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ foreach ($tests as $test) {
1717
===DONE===
1818
<?php exit(0); ?>
1919
--EXPECTF--
20+
Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a float is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d
21+
22+
Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a float is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d
23+
24+
Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a float is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d
2025
object(MongoDB\BSON\UTCDateTime)#%d (%d) {
2126
["milliseconds"]=>
2227
string(13) "1416445411987"

0 commit comments

Comments
 (0)