This repository was archived by the owner on May 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 815
In Zend_Db_Table_Abstract throwing undefined property, interrrupting scripts #720
Copy link
Copy link
Open
Labels
Description
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'];
}
}
}
...