I am trying to port a php application to .net and while reviewing the php code I came across a snippet which is a bit confusing. The block shown below
$cur_xml_valid = 'N';
$GenerateXml[] = "<J>";
$seq ++;
$GenerateXml[] = "<ANumber>" . $seq . "</ANumber>";
$GenerateXml[] = "<Customer>" . str_replace(array('&','>','<','"','\''), array('&','>','<','"','''), $invoice['customer']) . "</Customer>";
$GenerateXml[] = "<CompletionDate>" . str_replace(' ', 'T', $invoice['DateCreated']) . "</CompletionDate>";
$GenerateXml[] = "<OrderNumber>" . $invoice['SO'] . "</OrderNumber>";
$GenerateXml[] = "<OrderType>" . $invoice['type'] . "</OrderType>";
$GenerateXml[] = "<Comments>" . str_replace(array('&','>','<','"','\''), array('&','>','<','"','''), $invoice['Comments']) . "</Comments>";
$cur_xml_valid = 'Y';
if ($cur_xml_valid == 'N') {
$sqlxmlmismatch = "INSERT INTO xml_log (No,LogDesc) VALUES ( '$invoice_no','DOES NOT EXIST IN FILES (" . $invoice['Address'] . ")')";
$resultxmlmismatch = $db->query($sqlxmlmismatch);
$objWorksheet->getCell("BH$start_row")->setValue('DOES NOT EXIST IN FILES - NOT SENT');
}
Initially $cur_xml_valid is set to 'N' and after building up some xml string it is then set to 'Y'. Right after an if condition evaluates whether $cur_xml_valid is 'N' or not.
Q. Please confirm this is just bad code and $cur_xml_valid will never set to 'Y' if an error occurs. The whole execution stops in php if an error occurs, assuming there is no try/catch blocks?
Q. For a normal flow (without an exception) $cur_xml_valid will always get set to 'Y'.
$cur_xml_validthing doesn't make sense either.. (that I can see)