#14 _convertToAny does not encode boolean false correctly

open
nobody
PHP SForce (3)
5
2007-03-20
2007-03-20
ed_d
No

Basically, __convertToAny is using a simple string cast to create the custom <any> XML for fields. Since boolean FALSE in PHP equals blankstring '' in PHP, a checkbox field with false specified is translated to :

<checkbox__c></checkbox__c>

while salesforce requires '0' or 'false'.

Patch (on previous bug patch)

private function _convertToAny($fields) {
$XML = new XMLWriter();
$XML->openMemory();
foreach ($fields as $key => $value){
if($value === FALSE){
$value = '0';
}
$XML->writeElement($key, $value);
}

return $XML->outputMemory(TRUE);
}

Patch (code as is)

private function _convertToAny($fields) {
$anyString = '';
foreach ($fields as $key => $value) {
if($value === FALSE){
$value = '0';
}
$anyString = $anyString . '<' . $key . '>' . $value . '</' . $key . '>';
}
return $anyString;
}

Discussion