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

Issue Type: Bug Created: 2008-09-03T23:07:53.000+0000 Last Updated: 2009-09-17T15:36:04.000+0000 Status: Resolved Fix version(s): Reporter: Karl Katzke (karlkatzke) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Table

Related issues: - ZF-3837



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:

<pre class="highlight">

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:

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


<pre class="highlight">
        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.


Posted by Benjamin Eberlei (beberlei) on 2009-09-17T15:35:39.000+0000

Marked as duplicate

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.