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

Phalcon\Mvc\Model\Resultset\Simple::toArray() gives wrong result if empty #1377

Closed
lunaticPenguin opened this issue Oct 13, 2013 · 6 comments

Comments

@lunaticPenguin
Copy link

Phalcon\Mvc\Model\Resultset\Simple::toArray() method gives wrong result if empty.
It returns a correct array if not empty, and null if empty instead of an empty array (array()).

Here is the doc associated to the interface Phalcon\Mvc\Model\ResultsetInterface :

Returns a complete resultset as an array, if the resultset has a big number of rows
it could consume more memory than currently it does.
@return array
public function toArray();

@ghost
Copy link

ghost commented Oct 13, 2013

What version of Phalcon do you use?

@lunaticPenguin
Copy link
Author

The version 1.2.3

@ghost
Copy link

ghost commented Oct 13, 2013

Could you please try this patch and see if it works for you:

diff --git a/ext/mvc/model/resultset/simple.c b/ext/mvc/model/resultset/simple.c
index 3be317d..06d3c7d 100644
--- a/ext/mvc/model/resultset/simple.c
+++ b/ext/mvc/model/resultset/simple.c
@@ -336,6 +336,10 @@ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, toArray){
                phalcon_fast_count(row_count, records TSRMLS_CC);
                phalcon_update_property_this(this_ptr, SL("_count"), row_count TSRMLS_CC);
            }
+           else {
+               PHALCON_INIT_NVAR(records);
+               array_init(records);
+           }
        }
    }

@lunaticPenguin
Copy link
Author

After changes and build of changes, it still doesn't work.

@ghost
Copy link

ghost commented Oct 14, 2013

Did you build Phalcon from ext/ or from build/?

If from build/, please build it from ext/:

cd ext
phpize
./configure
make
sudo make install

If from ext/, could you please attach a test case reproducing the issue?

@lunaticPenguin
Copy link
Author

Aww! I built it from build/, sorry about that. I just did what the part http://docs.phalconphp.com/en/latest/reference/install.html#compilation is describing.

Build from ext/ it works fine. You fixed it. :)
Thanks for your reactivity. Should I close the thread ?

@ghost ghost mentioned this issue Oct 14, 2013
phalcon pushed a commit that referenced this issue Oct 15, 2013
@phalcon phalcon closed this as completed Oct 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant