Skip to content
This repository has been 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
pobrejuanito opened this issue Sep 14, 2016 · 1 comment

Comments

@pobrejuanito
Copy link

pobrejuanito commented Sep 14, 2016

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'];
                    }
                }
            }
  ...

tavy315 added a commit to tavy315/zendframework1 that referenced this issue Sep 26, 2016
@froschdesign
Copy link
Member

We are sorry, but ZF1 reaches its End of Life (EOL).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants