-
Notifications
You must be signed in to change notification settings - Fork 209
PHPC-2457 Fix modifiers and other Query options by reference #1694
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ static bool php_phongo_query_opts_append_document(bson_t* opts, const char* opts | |
zval* value = php_array_fetch(zarr, zarr_key); | ||
bson_t b = BSON_INITIALIZER; | ||
|
||
ZVAL_DEREF(value); | ||
if (Z_TYPE_P(value) != IS_OBJECT && Z_TYPE_P(value) != IS_ARRAY) { | ||
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"%s\" %s to be array or object, %s given", zarr_key, zarr_key[0] == '$' ? "modifier" : "option", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(value)); | ||
return false; | ||
|
@@ -333,6 +334,7 @@ bool phongo_query_init(zval* return_value, zval* filter, zval* options) | |
if (php_array_existsc(options, "modifiers")) { | ||
modifiers = php_array_fetchc(options, "modifiers"); | ||
|
||
ZVAL_DEREF(modifiers); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be done by |
||
if (Z_TYPE_P(modifiers) != IS_ARRAY) { | ||
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"modifiers\" option to be array, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(modifiers)); | ||
return false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--TEST-- | ||
PHPC-2457: Query modifiers can be passed reference | ||
--FILE-- | ||
<?php | ||
|
||
$modifiers = ['$orderby' => ['x' => 1]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You noted the following error in PHPC-2457:
The exception originates from |
||
|
||
$query = new MongoDB\Driver\Query([], [ | ||
'modifiers' => &$modifiers, | ||
]); | ||
|
||
var_dump($query); | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECTF-- | ||
Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s | ||
object(MongoDB\Driver\Query)#1 (3) { | ||
["filter"]=> | ||
object(stdClass)#2 (0) { | ||
} | ||
["options"]=> | ||
object(stdClass)#4 (1) { | ||
["sort"]=> | ||
object(stdClass)#3 (1) { | ||
["x"]=> | ||
int(1) | ||
} | ||
} | ||
["readConcern"]=> | ||
NULL | ||
} | ||
===DONE=== |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--TEST-- | ||
PHPC-2457: Query options can be passed reference | ||
--FILE-- | ||
<?php | ||
|
||
$collation = ['locale' => 'fr_FR', 'strength' => 2]; | ||
$let = ['x' => 1]; | ||
$sort = ['_id' => 1]; | ||
|
||
$query = new MongoDB\Driver\Query([], [ | ||
'collation' => &$collation, | ||
'let' => &$let, | ||
'sort' => &$sort, | ||
]); | ||
|
||
var_dump($query); | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
object(MongoDB\Driver\Query)#1 (3) { | ||
["filter"]=> | ||
object(stdClass)#2 (0) { | ||
} | ||
["options"]=> | ||
object(stdClass)#6 (3) { | ||
["collation"]=> | ||
object(stdClass)#3 (2) { | ||
["locale"]=> | ||
string(5) "fr_FR" | ||
["strength"]=> | ||
int(2) | ||
} | ||
["let"]=> | ||
object(stdClass)#4 (1) { | ||
["x"]=> | ||
int(1) | ||
} | ||
["sort"]=> | ||
object(stdClass)#5 (1) { | ||
["_id"]=> | ||
int(1) | ||
} | ||
} | ||
["readConcern"]=> | ||
NULL | ||
} | ||
===DONE=== |
Uh oh!
There was an error while loading. Please reload this page.