Skip to content

Commit d0d718e

Browse files
committed
PHPC-2443: Deprecate passing string values to UTCDateTime constructor
1 parent 5597dfb commit d0d718e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/BSON/UTCDateTime.c

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

206206
case IS_STRING:
207+
php_error_docref(NULL, E_DEPRECATED, "Creating a %s instance with a string is deprecated and be removed in ext-mongodb 2.0", ZSTR_VAL(php_phongo_utcdatetime_ce->name));
208+
207209
php_phongo_utcdatetime_init_from_string(intern, Z_STRVAL_P(milliseconds), Z_STRLEN_P(milliseconds));
208210
return;
209211
}

tests/bson/bson-utcdatetime-008.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
MongoDB\BSON\UTCDateTime construction from 64-bit integer as string
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/basic.inc';
7+
8+
$utcdatetime = new MongoDB\BSON\UTCDateTime('1416445411987');
9+
10+
var_dump($utcdatetime);
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECTF--
16+
Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and be removed in ext-mongodb 2.0 %S
17+
object(MongoDB\BSON\UTCDateTime)#%d (%d) {
18+
["milliseconds"]=>
19+
string(13) "1416445411987"
20+
}
21+
===DONE===

0 commit comments

Comments
 (0)