ZF-3349: $table->find() method miss matching rows

Description

API Doc says that .find() method accepts arrays of arguments (one per primary key field), but it does not specify that these arrays MUST NOT be hash, otherwise array entries are skipped and .find() does not return all matching rows! Very serious bug!

Ex: $id = array(0=>1, 1=>2, 99=>3); mytable.find($id) will skip value '3' because its key is not 2. Generated $whereClause is:


where expected clause is:

This comes from the following code, in Zend_Db_Table_Abstract, public function find():


            for ($i = 0; $i < count($keyValues); ++$i) {
                $whereList[$i][$keyPosition] = $keyValues[$i];
            }

which could be replaced by:


           $i = 0;
            foreach ($keyValues as $v) {
                $whereList[$i++][$keyPosition] = $v;
            }

Great framework anyway! Keep up, guys! Thx

Comments

The arguments array provide to find() need no keys. So , I think , a better way is to use array_values() in find() method to evevy arguments array, make sure they all index by 0 , 1 , 2 .....

Please evaluate and fix/categorize as necessary.

I believe this is not an issue, and should be resolved as such

While i think this could go either way, I think its best to perhaps change the behavior under the hood to use array_values() instead of using the for loop. This would ensure that only values are used.

Changing to "Trivial", "Nice To Have", can go in "Next Mini Release", about 30m of real work

Fixed in trunk in r17815 and in release branch 1.9 in r17816