Issues

ZF-6721: Bug if Join is called with an non-associative array for tablename

Issue Type: Bug Created: 2009-05-19T02:26:43.000+0000 Last Updated: 2011-08-04T09:48:39.000+0000 Status: Resolved Fix version(s): - 1.8.3 (09/Jun/09)

Reporter: Jérôme Melis (stopi) Assignee: Satoru Yoshida (satoruyoshida) Tags: - Zend_Db_Select

Related issues: Attachments:

Description

While using ZF 1.7.6, I found this bug. It seems still present in 1.8.1

<pre class="highlight">
protected function _join($type, $name, $cond, $cols, $schema = null)

Exctracting code from ZF 1.8.1, this function cannot be called with a non-associative array for $name parameter because :

<pre class="highlight">

757        if (empty($name)) {
758            $correlationName = $tableName = '';
759        } else if (is_array($name)) {
760            // Must be array($correlationName => $tableName) or array($ident, ...)
761            foreach ($name as $_correlationName => $_tableName) {
762                if (is_string($_correlationName)) {
763                    // We assume the key is the correlation name and value is the table name
764                    $tableName = $_tableName;
765                    $correlationName = $_correlationName;
766                } else {
767                    // We assume just an array of identifiers, with no correlation name
768                    $tableName = $name;
769                    $correlationName = $this->_uniqueCorrelation($tableName);
770                }
771                break;
772            }
773        } else if ($name instanceof Zend_Db_Expr|| $name instanceof Zend_Db_Select) {
774            $tableName = $name;
775            $correlationName = $this->_uniqueCorrelation('t');
776        } else if (preg_match('/^(.+)\s+AS\s+(.+)$/i', $name, $m)) {
777            $tableName = $m[1];
778            $correlationName = $m[2];
779        } else {
780            $tableName = $name;
781            $correlationName = $this->_uniqueCorrelation($tableName);
782        }
783
784        // Schema from table name overrides schema argument
785        if (!is_object($tableName) && false !== strpos($tableName, '.')) {
786            list($schema, $tableName) = explode('.', $tableName);
787        }

As you can easily see, if :

<pre class="highlight">
$name = array('test');

The code pass over line 759 then, in foreach do only once the loop, going in else part (line 768). I think there is at least a bug on this line 768. Correct code should be :

<pre class="highlight">
768                    $tableName = $_tableName;

Then maybe other lines should change after, I don't know... But I'm sure of this bug because if you continue to follow the PHP code, you see that the next use of $tableName is on line 785. And at this point, $tableName contains array('test'). So is_object($tableName) is false, then strpos($tableName, '.') raise an error, because $tableName is not a string, but an array.

Hope solving this issue will help to solve other problems related to JOIN's feature.

Comments

Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2009-05-30T20:15:29.000+0000

Thank You for Your information. It helps me BIG! :-) Solved in SVN r15843

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