Issues

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

Issue Type: Bug Created: 2008-03-01T12:32:17.000+0000 Last Updated: 2008-09-02T10:39:22.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: Max Gordon (mgordon) Assignee: Simon Mundy (peptolab) Tags: - Zend_Db

Related issues: Attachments:

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:

<pre class="highlight">
$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:

<pre class="highlight">
$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():

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

Comments

Posted by Wil Sinclair (wil) on 2008-03-25T20:43:56.000+0000

Please categorize/fix as needed.

Posted by Simon Mundy (peptolab) on 2008-05-30T18:54:53.000+0000

Resolved in r9577

Posted by Wil Sinclair (wil) on 2008-09-02T10:39:22.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts