Skip to content
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

MongoCollection->aggregate makes php error with pipeline operators given as arguments #114

Closed
pilou opened this issue Jun 14, 2016 · 4 comments
Labels
Milestone

Comments

@pilou
Copy link

pilou commented Jun 14, 2016

The thing is the first argument is overwritten. :(

Bad code:

        if (! TypeConverter::isNumericArray($pipeline)) {
            $pipeline = [];
            $options = [];

            $i = 0;
            foreach (func_get_args() as $operator) {

Good code:

        if (! TypeConverter::isNumericArray($pipeline)) {
            $operators = func_get_args();
            $pipeline = [];
            $options = [];

            $i = 0;
            foreach ($operators as $operator) {

If the func_get_args is called after$pipeline = [], the first value of the array will be an empty array.

Test case, and pull request is in progress.

pilou pushed a commit to pilou/mongo-php-adapter that referenced this issue Jun 14, 2016
This method should accept a variable amount of pipeline operators
MongoCollection::aggregate ( array $op [, array $op [, array $... ]] )

alcaeus#114
http://www.php.net/manual/en/mongocollection.aggregate.php
alcaeus pushed a commit that referenced this issue Jun 16, 2016
This method should accept a variable amount of pipeline operators
MongoCollection::aggregate ( array $op [, array $op [, array $... ]] )

#114
http://www.php.net/manual/en/mongocollection.aggregate.php
@alcaeus
Copy link
Owner

alcaeus commented Jun 16, 2016

Hah, took me a while to realise this was only occuring on PHP 7, not on 5.6. I fixed it and this will be included in the upcoming 1.0.4 release. I'm waiting for feedback on #116; once that is merged I'll release a fixed version.

@alcaeus alcaeus added the bug label Jun 16, 2016
@alcaeus alcaeus added this to the 1.0.4 milestone Jun 16, 2016
@pilou
Copy link
Author

pilou commented Jun 16, 2016

Ohh, maybe we found a PHP bug?
I think those guys didnt intend to change the behaviour of funct_get_args.

@pilou
Copy link
Author

pilou commented Jun 16, 2016

They intended to do the change http://php.net/manual/en/function.func-get-args.php see Example #3

@alcaeus
Copy link
Owner

alcaeus commented Jun 17, 2016

Thanks for following up on it, good to know 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants