user1506157
user1506157

Reputation: 115

Zend framework - PDO source code

I have a little question just for educational purpose...

I was digging into Zend Framework's code, in order to learn how it works "from the inside", and I stopped at this little piece of code : (Their implementation of bindParam() from PDO) :

 /**
 * Binds a parameter to the specified variable name.
 *
 * @param mixed $parameter Name the parameter, either integer or string.
 * @param mixed $variable  Reference to PHP variable containing the value.
 * @param mixed $type      OPTIONAL Datatype of SQL parameter.
 * @param mixed $length    OPTIONAL Length of SQL parameter.
 * @param mixed $options   OPTIONAL Other options.
 * @return bool
 */
public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
    if (!is_int($parameter) && !is_string($parameter)) {
        /**
         * @see Zend_Db_Statement_Exception
         */
        require_once 'Zend/Db/Statement/Exception.php';
        throw new Zend_Db_Statement_Exception('Invalid bind-variable position');
    }

    $position = null;
    if (($intval = (int) $parameter) > 0 && $this->_adapter->supportsParameters('positional')) {
        if ($intval >= 1 || $intval <= count($this->_sqlParam)) {
            $position = $intval;
        }
    } else if ($this->_adapter->supportsParameters('named')) {
        if ($parameter[0] != ':') {
            $parameter = ':' . $parameter;
        }
        if (in_array($parameter, $this->_sqlParam) !== false) {
            $position = $parameter;
        }
    }

    if ($position === null) {
        /**
         * @see Zend_Db_Statement_Exception
         */
        require_once 'Zend/Db/Statement/Exception.php';
        throw new Zend_Db_Statement_Exception("Invalid bind-variable position '$parameter'");
    }

    // Finally we are assured that $position is valid
    $this->_bindParam[$position] =& $variable;
    return $this->_bindParam($position, $variable, $type, $length, $options);
}

The thing that I don't understand, is that at the end of the function, they return

return $this->_bindParam($position, $variable, $type, $length, $options)

which is declared as an array ...

     /**
     * Query parameter bindings; covers bindParam() and bindValue().
     *
     * @var array
     */
    protected $_bindParam = array();

How can they return an array and pass parameters to it ?

Moreover, I can find any condition to stop the recursion...

You can find the link for the file here :

http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Db/Statement.php

Upvotes: 2

Views: 402

Answers (1)

doydoy44
doydoy44

Reputation: 5772

Zend_Db_Statement is an abstract class.
Unless I am mistaken, all classes that inherit from Zend_Db_Statement declare a _bindParam() method.

for example in Zend_Db_Statement_Pdo:

class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggregate
{
...

    protected function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
    {
...
    }
}

Upvotes: 1

Related Questions