Bug #20291 [Com]: Ignored in update $dao->field = 0

From: Date: Fri, 06 Mar 2015 00:35:24 +0000
Subject: Bug #20291 [Com]: Ignored in update $dao->field = 0
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-11256@lists.php.net to get a copy of this message
Edit report at http://pear.php.net/bugs/bug.php?id=20291&edit=1 ID: 20291 Comment by: mmn Reported By: mmn at hethane dot se Summary: Ignored in update $dao->field = 0 Status: Open Type: Bug Package: DB_DataObject Operating System: windows8 Package Version: 1.11.3 PHP Version: 5.5.3 New Comment: I just ran into this issue. The problem is that "disable_null_strings" will not only test against null _strings_ but anything that can be compared to false ('', 0, false...). Here is the code, starting around line 1345 in DB/DataObject.php (latest stable): if ((!isset($this->$k) || ($v == 1 && $this->$k == '')) && $ignore_null ) { continue; } If you change $this->$k == '' to $this->$k === '' a type-aware comparison will be made. Since "&& $ignore_null" is derived from the config value of "disable_null_strings" we only want to disable null _strings_, not anything that results in false. For example, this is true: 0 == '' which causes the problem of trying to set a value to 0 using default "disable null strings" unless the 0 value is given _as a string_ ('0'). To fix this properly everywhere, both the "update" and the "insert" functions need to be fixed identically. So a quick solution to this problem is to make the type-aware comparison with three equal signs: $this->$k === '' The code in the "insert" function looks like this around line 1097, you can see it is exactly the same: if ( (!isset($this->$k) || ($v == 1 && $this->$k == '')) && $ignore_null ) { continue; } After fixing it should be: if ( (!isset($this->$k) || ($v == 1 && $this->$k === '')) && $ignore_null ) { continue; } Previous Comments: ------------------------------------------------------------------------ [2014-06-09 04:06:14] alan_k Can you test with the column as not null. Update the schema. It needs fixing but I need to be sure of the exact reason for it occurring ------------------------------------------------------------------------ [2014-06-06 13:21:07] yourchoicero But does not matter is null or not null. If I cannot set an integer, even 0, this it's a bug. Old version allow it. ------------------------------------------------------------------------ [2014-06-06 13:16:24] yourchoicero uti_nb_failed_login int(4) DEFAULT NULL, ------------------------------------------------------------------------ [2014-06-06 06:55:13] alan_k is 'field' defined as allow NULL (eg. does not have NOT NULL) ------------------------------------------------------------------------ [2014-06-05 10:48:42] yourchoicero <div id="changeset"> <span class="removed">-Operating System: update</span> <span class="added">+Operating System: windows8</span> </div> ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://pear.php.net/bugs/bug.php?id=20291 -- Edit this bug report at http://pear.php.net/bugs/bug.php?id=20291&edit=1

« previous php.pear.bugs (#11256) next »