ZF-4183: Zend_Db_Table_Abstract::insert() uses isset instead of empty to decide when to return pkey


Line 822-824 of current trunk tests for !isset() when empty() would be more appropriate, as users may be submitting the validated array of values from a form that may include an id field.

When submitting the values of a form, using an array as such:


The current code will not return the sequence/identity field of 'id' because it fails the !isset($array['id']) test on line 822. A !isset() test will unreliably return true on an empty but set array field. Using empty() provides better reliability for users.


Change code from:

        if ($this->_sequence === true && !isset($data[$pkIdentity])) {
                $data[$pkIdentity] = $this->_db->lastInsertId();


        if ($this->_sequence === true && empty($data[$pkIdentity])) {
                $data[$pkIdentity] = $this->_db->lastInsertId();

I'm not sure when this changed because I hadn't tested this functionality since 1.5 was a new release.


Marked as duplicate