Issues

ZF-2778: Error in Zend_Db_Table::find() & Zend_Filter_Inflector::filter() not initiating empty array() b4 setting value

Description

PHP acts unpredictably when arrays are not initiated. Any array variable should be set to array() before setting any keys, ex. $my_var[1] = "foo" should be preceded with a $my_var = array(). I've found two errors based on this in 1.5RC1

In Zend_Db_Table::find() the following section should be changed:


$whereList = array();
$numberTerms = 0;
foreach ($args as $keyPosition => $keyValues) {
    // Coerce the values to an array.
    // Don't simply typecast to array, because the values
    // might be Zend_Db_Expr objects.
    if (!is_array($keyValues)) {
         $keyValues = array($keyValues);
     }

     if ($numberTerms == 0) {
          $numberTerms = count($keyValues);
     } else if (count($keyValues) != $numberTerms) {
          require_once 'Zend/Db/Table/Exception.php';
          throw new Zend_Db_Table_Exception("Missing value(s) for the primary key");
     }

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

to:


$whereList = array();
$numberTerms = 0;
foreach ($args as $keyPosition => $keyValues) {
    // Coerce the values to an array.
    // Don't simply typecast to array, because the values
    // might be Zend_Db_Expr objects.
    if (!is_array($keyValues)) {
         $keyValues = array($keyValues);
     }

     if ($numberTerms == 0) {
          $numberTerms = count($keyValues);
     } else if (count($keyValues) != $numberTerms) {
          require_once 'Zend/Db/Table/Exception.php';
          throw new Zend_Db_Table_Exception("Missing value(s) for the primary key");
     }

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

On my computer the "$whereList[$i][$keyPosition] = $keyValues[$i];" creates a semi-random array that contains 3 elements instead of one element causin a annoying warning.

The same error seems to occur in Zend_Filter_Inflector::filter():


$processedParts = array(); // Add this row before the foreach statement
foreach ($this->_rules as $ruleName => $ruleValue) {...}

Comments

Please categorize/fix as needed.

Resolved in r9577

Updating for the 1.6.0 release.