PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject » Bug #7353

Boolean 'true' NOT properly evaluated

Details

Submitted2006-04-10 02:51 UTC
Frompkeane at mail dot utexas dot edu
Assignedalan_k
StatusClosed
PackageDB_DataObject
PHP Version4.4.2
OSGentoo Linux
Roadmaps(Not assigned)

Comments

[2006-04-10 02:51 UTC] pkeane at mail dot utexas dot edu

Description:
------------
[NOTE this bug seems to have been introduced when BUG #4535 was patched. My proposed fix should STILL address the issue indicated with bug #4535, but with a patch that operates properly)]

If an attribute of an object has a value of TRUE (php boolean) and you do a $my_object->find(), the boolean value TRUE will not be properly evaluated and you may, in fact, retrieve objects in which that attribute has a value of FALSE. The reason is a bit of code in DB/DataObject.php (I believe this code is meant specifically to deal with PostgreSQL) which creates the query. At one point there is a test,

if ($this->$k == 'f') then ...

but in fact, that statement will evaluate to TRUE if $this->$k is set to boolean TRUE because if so, the 'f' is cast to boolean before the comparison is made (and the string 'f' evaluates to true). The code SHOULD be either:
if ((string) $this->$k == 'f') then ...
OR
if ($this->$k === 'f') then ...
either of which works properly

The problem line appears in the functions:
insert (line 998)
update (line 1238)
_build_condition (line 2460)
joinAdd (line 3236)

[By the way, I think DB/DataObjects is an incredibly fantastic PEAR module and has saved me MANY hours of work.]

[2006-04-10 03:23 UTC] pkeane at mail dot utexas dot edu

Excellent. Thanks for the speedy response and the great package.