ZF-2953: Zend_Db_Table_Abstract->insert returns empty value

Issue Type: Patch Created: 2008-03-24T06:05:20.000+0000 Last Updated: 2011-04-28T17:59:12.000+0000 Status: Resolved Fix version(s): - 1.11.3 (01/Feb/11)

Reporter: Marcos Gil Fuertes (marcis) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Table

Related issues: - ZF-3837

Attachments: - zf-2953.patch


The "insert" method from "Zend_Db_Table_Abstract" (extended for MySql) doesn't return the value of the "most recent ID" when it receives an empty value ('') for this primary key. The register is properly inserted in the db.

It checks if the value is null:

<pre class="highlight">
         * If the primary key can be generated automatically, and no value was
         * specified in the user-supplied data, then omit it from the tuple.
        if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {

Maybe, it should check if the value is "empty".


Posted by Wil Sinclair (wil) on 2008-03-25T20:43:56.000+0000

Please categorize/fix as needed.

Posted by Marcos Gil Fuertes (marcis) on 2008-03-27T07:52:30.000+0000

Fix Version Priority: Must Have ?

Posted by Wil Sinclair (wil) on 2009-01-06T10:48:23.000+0000

No action on this issue for too long. I'm reassigning to Ralph for re-evaluation and categorization.

Posted by Ralph Schindler (ralph) on 2009-01-10T11:40:08.000+0000

Are you saying that

<pre class="highlight">
if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {

should become:

<pre class="highlight">
if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] == null) {
if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] == '') {


Posted by Marcos Gil Fuertes (marcis) on 2009-01-12T01:54:58.000+0000

Maybe, you could use the "empty" function...

Posted by Fabio Almeida (fabius) on 2009-02-10T19:44:30.000+0000

I confirm this bug, still alive in ZF 1.7.4, also confirm that the "empty instead of null" check works for me. It's frustrating to see such a simple issue being carried over between releases for so long.

Posted by Fabio Almeida (fabius) on 2009-03-02T20:59:25.000+0000

Fix version bumped up to 1.7.5. ZF 1.7.5 is released. The bug is still there.

Fix version bumped up to 1.7.6. ZF 1.7.6 is released. The bug is still there.

I don't wanna be a whiner, but am I missing something here? It's such an easy fix (just one line of code!) and it's so annoying to have to fix it over and over with each ZF release. Why is it getting so little attention?

Posted by Fabio Almeida (fabius) on 2009-03-13T13:08:35.000+0000

I didn't take the time for a deeper check, but I believe these two issues are related, if not the same.

Posted by Marcos Gil Fuertes (marcis) on 2009-05-25T02:18:39.000+0000

Maybe, I'll become a contributor to solve this "line of code"...

Posted by Mike Willbanks (digitalstruct) on 2009-06-18T21:30:50.000+0000

Actually using the function empty would cause unpredicted results. The value of '0' is valid in the auto-incrementing sequence therefore this would not be an adequate fix. Although the correct fix would be to utilize strlen. Will work on writing the patch and the test case for this in the next day or so.

Posted by Mike Willbanks (digitalstruct) on 2009-06-23T17:55:47.000+0000

Attached patch and test case for the issue.

Posted by Marcos Gil Fuertes (marcis) on 2010-12-30T06:35:03.000+0000

Almost 3 years later, the issue is still open... solve it or close it, please! It's only one line of code!!!

Posted by Fabio Almeida (fabius) on 2011-01-03T16:35:24.000+0000

Plus, everytime a new release is out we have to patch it to fix this issue. Annoying to say the least!

Posted by Ralph Schindler (ralph) on 2011-01-05T13:57:34.000+0000

I've added a fix for this issue in r23621 in trunk.

Please test your applications against this. The fix does not use empty() or any other type in-specific routines to determine if a PK was included. Instead, it uses a smaller subset of valid primary key value types. For example, '0' and 0 are valid primary keys that would not pass an empty() test.

If this works for everyone, I will merge to 1.11.


Posted by Ralph Schindler (ralph) on 2011-01-22T08:02:24.000+0000

Resolved in trunk at r23621 and in branch 1.11 at 23657

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.