Skip to content
This repository was archived by the owner on May 16, 2018. It is now read-only.
This repository was archived by the owner on May 16, 2018. It is now read-only.

In Zend_Db_Table_Abstract throwing undefined property, interrrupting scripts #720

Open

Description

@pobrejuanito

In Zend_Db_Table_Abstract, in two protected methods (setupDatabaseAdapter(), _setupPrimaryKey()) there is a condition that checks if class property is defined. It sometimes throws undefined property, stopping scripts, breaking apps.

In _setupDatabaseAdapter()

If (!$this->_db) condition will sometime throw undefined property and stop the script. The correct way to check this condition should be if (!isset($this->_db)) which doesn't throw undefined property

Same thing happens in _setupPrimaryKey() if (!$this->_primary) should be written as if (!isset($this->_primary)) to avoid getting undefined property notice.

if (!isset($this->_primary))

Zend_Db_Table_Abstract

protected function _setupDatabaseAdapter()
    {
    // if (!$this->db)) { // current
        if (!isset($this->_db)) {   // better way: prevents undefined property
            $this->_db = self::getDefaultAdapter();
            if (!$this->_db instanceof Zend_Db_Adapter_Abstract) {
                require_once 'Zend/Db/Table/Exception.php';
                throw new Zend_Db_Table_Exception('No adapter found for ' . get_class($this));
            }
        }
    }
 protected function _setupPrimaryKey()
    {
    //  if (!$this->_primary)) {  <-- currently
        if (!isset($this->_primary)) {  // better way: prevents undefined property
            $this->_setupMetadata();
            $this->_primary = array();
            foreach ($this->_metadata as $col) {
                if ($col['PRIMARY']) {
                    $this->_primary[ $col['PRIMARY_POSITION'] ] = $col['COLUMN_NAME'];
                    if ($col['IDENTITY']) {
                        $this->_identity = $col['PRIMARY_POSITION'];
                    }
                }
            }
  ...

Activity

  1. froschdesign commented on Oct 1, 2016

    @froschdesign
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions