Home » Database » DB_DataObject » Bug #5818
Validation fails for field set with NULL value string 'null'
Details
| Submitted | 2005-10-28 22:50 UTC |
|---|---|
| From | deckhoff at valetpay dot com |
| Assigned | alan_k |
| Status | Closed |
| Package | DB_DataObject |
| PHP Version | 4.4.0 |
| OS | Any |
| 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.