Skip to content

PHPC-2464: Emit deprecation notice for negative "limit" Query option #1710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/MongoDB/Query.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ static bool php_phongo_query_init_limit_and_singlebatch(php_phongo_query_t* inte
if (php_array_fetchc_long(options, "limit") < 0) {
zend_long limit = php_array_fetchc_long(options, "limit");

php_error_docref(NULL, E_DEPRECATED, "Support for negative \"limit\" values is deprecated and will be removed in ext-mongodb 2.0");

if (!BSON_APPEND_INT64(intern->opts, "limit", -limit)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error appending \"limit\" option");
return false;
Expand Down
3 changes: 3 additions & 0 deletions tests/query/query-ctor-005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var_dump(new MongoDB\Driver\Query(
===DONE===
<?php exit(0); ?>
--EXPECTF--
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
object(MongoDB\Driver\Query)#%d (%d) {
["filter"]=>
object(stdClass)#%d (%d) {
Expand All @@ -36,6 +37,8 @@ object(MongoDB\Driver\Query)#%d (%d) {
["readConcern"]=>
NULL
}

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
object(MongoDB\Driver\Query)#%d (%d) {
["filter"]=>
object(stdClass)#%d (%d) {
Expand Down
3 changes: 2 additions & 1 deletion tests/query/query-ctor_error-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ echo throws(function() {
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
--EXPECTF--
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
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Negative "limit" option conflicts with false "singleBatch" option
===DONE===
1 change: 1 addition & 0 deletions tests/server/server-executeQuery-007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var_dump(iterator_to_array($cursor));
===DONE===
<?php exit(0); ?>
--EXPECTF--
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
bool(true)
bool(true)
array(2) {
Expand Down