PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB_DataObject » Bug #5818

Validation fails for field set with NULL value string 'null'

Details

Submitted2005-10-28 22:50 UTC
Fromdeckhoff at valetpay dot com
Assignedalan_k
StatusClosed
PackageDB_DataObject
PHP Version4.4.0
OSAny
Roadmaps(Not assigned)

Comments

[2005-10-28 22:50 UTC] deckhoff at valetpay dot com

Description:
------------
Currently, if the string 'null' is used to set a field to a SQL NULL value, the validation will fail if the field in question is of type DB_DATAOBJECT_INT.

Test script:
---------------
$user->affiliateId = 'null';
$ret = $user->validate();

$ret['affiliateId'] always will be false.

Possible Patch for DB_DataObject::validate():

This code:

if (is_string($this->$key) && (strtolower($this->$key) == 'null') && ($val & DB_DATAOBJECT_NOTNULL)) {
$ret[$key] = false;
continue;
}

Should be something like:

if (is_string($this->$key) && (strtolower($this->$key) == 'null')) {
if ($val & DB_DATAOBJECT_NOTNULL) {
$this->debug( "'null' field not allowed", 'VALIDATION', 4);
$ret[$key] = false;
} else {
$this->debug( "'null' field allowed", 'VALIDATION', 4);
$ret[$key] = true;
}
continue;
}

Expected result:
----------------
If 'null' is used to set a field to SQL NULL, then this special case should be exempt from other validation checks such as Validate::number and Validate::string.

If 'null' should not be used for SQL NULL values, then a well documented alternative should be supplied.

Actual result:
--------------
Validation returns false for field.