ZF-180: Zend_Db_Table_Row: __get function maps incorrectly to _data

Issue Type: Bug Created: 2006-07-01T05:16:00.000+0000 Last Updated: 2007-07-05T14:43:12.000+0000 Status: Resolved Fix version(s): - 0.9.0 (17/Mar/07)

Reporter: Bjarte Kalstveit Vebjørnsen (bjarte) Assignee: Bill Karwin (bkarwin) Tags: - Zend_Db_Table

Related issues: Attachments:


I am unsure whether this is a problem with the pdo fetch function or if the problem is in the Zend_Db_Table_Row class. I'm guessing the first since I see that if you don't supply a data index in the config parameter to the constructor you use the array keys from $this->_info['cols'] as keys for the $this->_data member.

I changed the __get function to look for $camel in $this->_data instead of $under to get it to work, but it seems my array keys in $this->_data member is messed up: Shouldn't _data contain array('ID' => 35, 'FirmaID' => 0) ?

Zend_Db_Table_Row Object ( [_data:protected] => Array ( [id] => 35 [firmaid] => 0 ... ) [_info:protected] => Array ( [name] => cPerson [cols] => Array ( [ID] => id [FirmaID] => firmaid ... ) [primary] => ID ) )


Posted by Bjarte Kalstveit Vebjørnsen (bjarte) on 2006-07-01T07:58:59.000+0000

Sorry, I should have done some checks with PDO first. I see you force lower-case in the Zend_Db_Adapter_Pdo_Abstract, so the problem is in the Zend_Db_Table_Row's __get function then ?

return $this->_data[$under];

should be:

return $this->_data[$camel];

Posted by Mark Godden (xeo) on 2006-07-02T07:38:08.000+0000


I belive i have expiranced the same problem today please allow me to explain:

I have noticed that the array $this->_info['cols'] on line 93 of Row.php returns a array of database field names mapped to lower case copies of these field names.

This array is then searched for the supplied field name in $camel and $under is assigned the true field names returned from the DB.

However all of $this_data's keys/fieldnames are lower case to same as $this->info['cols'], this results in a error as $under is set to the true field names not a lower case version.


$camel = "clientid"

$this->_info['cols'] = Array ("ClientID" = "clientid")

$under = "ClientID"

$this->_data = Array ("clientid" = "1")

so we get an error when:

return $this->_data[$under]; AKA ($this->_data['ClientID'])

I have temp patched this on my copy by placing $under = strltolower($under);

however i belive there is a far better way to fix this just not got the time at the mo.

Hope all that makes sence

Posted by Bjarte Kalstveit Vebjørnsen (bjarte) on 2006-07-03T15:52:06.000+0000


Seems you have same problem as I. Kinda hard to know what the right solution is as the docs doesn't say anything about upper-case field names only lower-case with underscores. Since it says you should use camelCase instead of underscores to access the row properties it made me thinking it would make a whole lot more sense to do $row->ClientID than $row->clientid. Thats what i initalially expected it to do when i started with zend_db_table, but it threw an exception at me.

Posted by Shannon Wynter (freman) on 2006-09-06T06:22:25.000+0000

I'm also experiencing this.

my table contains ID, Name, Username, Host

if I call $row->Name I get "exception 'Zend_Db_Table_Row_Exception' with message 'column 'Name' not in row'"

if I call $row->Name I get "Notice: Undefined index: Name in /home/freman/Documents/code/phprdiffbackup/trunk/htdocs/library/Zend/Db/Table/Row.php on line 96"

Posted by Charles Bump (cool_bump) on 2006-09-07T14:18:28.000+0000

I also experienced this issue and resolved it by making the following modifications:

====================================== The Zend_Db_Inflector's camelize method, IMO should not run unless the name actually has underscores in it. If it does run, it automatically returns a lowercase version of the name which causes some mismatching of field names:

Index: library/Zend/Db/Inflector.php

 public function camelize($name)
  • if (strpos($name, '_') <= 0) { + return $name; + } // lowercase all, underscores to spaces, and prefix with underscore. // (the prefix is to keep the first letter from getting uppercased

// in the next statement.)

In addition, the describeTable method in Zend_Db_Adapter_Pdo_Mysql does not work properly if the ATTR_CASE attribute is set to anything except CASE_LOWER. This is because, by default, MySQL capitalizes the field names in the description and this must then be lowercased to create the description array.

Index: library/Zend/Db/Adapter/Pdo/Mysql.php

    $descr = array();
    foreach ($result as $key => $val) {
  • $val = array_change_key_case($val); $descr[$val['field']] = array( 'name' => $val['field'],

'type' => $val['type'],

I hope this helps . . . .

Posted by Bill Karwin (bkarwin) on 2006-11-13T15:14:33.000+0000

Changing fix version to 0.8.0.

Posted by Bill Karwin (bkarwin) on 2007-01-05T17:06:24.000+0000

Recategorize as Zend_Db_Table component.

Posted by Bill Karwin (bkarwin) on 2007-03-15T23:40:02.000+0000

As of revision 3995, the use of inflectors has been eliminated from Zend_Db_Table.

Have you found an issue?

See the Overview section for more details.


© 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.