Skip to content

Commit 20fbbc0

Browse files
jmikolaalcaeus
andauthored
PHPC-2464: Emit deprecation notice for negative "limit" Query option (#1710)
Co-authored-by: Andreas Braun <git@alcaeus.org>
1 parent e53f85c commit 20fbbc0

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

src/MongoDB/Query.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ static bool php_phongo_query_init_limit_and_singlebatch(php_phongo_query_t* inte
209209
if (php_array_fetchc_long(options, "limit") < 0) {
210210
zend_long limit = php_array_fetchc_long(options, "limit");
211211

212+
php_error_docref(NULL, E_DEPRECATED, "Support for negative \"limit\" values is deprecated and will be removed in ext-mongodb 2.0");
213+
212214
if (!BSON_APPEND_INT64(intern->opts, "limit", -limit)) {
213215
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error appending \"limit\" option");
214216
return false;

tests/query/query-ctor-005.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var_dump(new MongoDB\Driver\Query(
2020
===DONE===
2121
<?php exit(0); ?>
2222
--EXPECTF--
23+
Deprecated: MongoDB\Driver\Query::__construct(): Support for negative "limit" values is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d
2324
object(MongoDB\Driver\Query)#%d (%d) {
2425
["filter"]=>
2526
object(stdClass)#%d (%d) {
@@ -36,6 +37,8 @@ object(MongoDB\Driver\Query)#%d (%d) {
3637
["readConcern"]=>
3738
NULL
3839
}
40+
41+
Deprecated: MongoDB\Driver\Query::__construct(): Support for negative "limit" values is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d
3942
object(MongoDB\Driver\Query)#%d (%d) {
4043
["filter"]=>
4144
object(stdClass)#%d (%d) {

tests/query/query-ctor_error-003.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ echo throws(function() {
1212
?>
1313
===DONE===
1414
<?php exit(0); ?>
15-
--EXPECT--
15+
--EXPECTF--
16+
Deprecated: MongoDB\Driver\Query::__construct(): Support for negative "limit" values is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d
1617
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
1718
Negative "limit" option conflicts with false "singleBatch" option
1819
===DONE===

tests/server/server-executeQuery-007.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var_dump(iterator_to_array($cursor));
2929
===DONE===
3030
<?php exit(0); ?>
3131
--EXPECTF--
32+
Deprecated: MongoDB\Driver\Query::__construct(): Support for negative "limit" values is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d
3233
bool(true)
3334
bool(true)
3435
array(2) {

0 commit comments

Comments
 (0)