ZF-21: Zend_Db_Table::find() - return values have inconsistent type


Zend_Db_Table::find($val) returns Zend_Db_Table_Rowset object when count((array)$val) > 1, and returns Zend_Db_Table_Row object when count((array)$val) <= 1.

I wrote following code,

$pkeys = getPKeysWithSomeConditions(); // return array of primary key $rowset = $table->find($pkeys); // $table is instance of Zend_Db_Table foreach ($rowset as $row) { // do something }

When getPKeysWithSomeConditions() returns array contains some elements, it works well, But if $pkeys contains only one element, it doesn't work. Because $rowset is instance of Zend_Db_Table_Row not instance of Zend_Db_Table_Rowset.

Isn't it more natural it returns always Zend_Db_Table_Rowset, when Zend_Db_Table::find($val) called with $val parameter that type is array ?

I wish to change Zend_Db_Table::find() method like this,

public function find($val)
    $key = $this->_primary;
    if (is_array($val)) {
        if (count($val)) {
            $where = array(
                "$key IN(?)" => $val,
        } else {
            $where = '0 = 1';  // always false condition
        $order = "$key ASC";
        return $this->fetchAll($where, $order);
    } else {
        $where = array(
            "$key = ?" => (isset($val) ? $val : ''),
        return $this->fetchRow($where);


This article is moved from fw-general ML. And I sent CLA by fax.


Changing fix version to 0.8.0.

See also ZF-557 for another confusing behavior of the find() method. We should resolve both of these.

Recategorize as Zend_Db_Table component.

As of revision 3995, the find() method always returns an object of type Zend_Db_Table_Rowset_Abstract.