这是IF语句。我想稍后访问timeStampCleaned变量。为什么我不能访问If语句中的变量?
if ($xmlRatesTime = '') {
$timeStampCleaned = date('j F Y H:i', $ratesTimeStamp); // Convert unix timestamp into date format
} else {
// ...
}
像这样:
if(empty($ratesTimeStamp)) {
$newXML = simplexml_load_file('cache/rates.xml');
$child = $newXML->addChild('currency');
$child->addAttribute('id', ''.$to.'');
$child->addChild('title', $toTitle);
$child->addChild('loc', $toLocation);
$child->addChild('rate', $finalRate);
$child->addChild('timestamp', $timeStamp);
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($newXML->asXML());
$newXMLdomCleaned = $dom->saveXML();
file_put_contents('cache/rates.xml', $newXMLdomCleaned);
}
但我得到的错误:
Notice: Undefined variable: timeStampCleaned in ...file... on line 208
从我的理解,如果报表是精细内访问变量。所以我不知道为什么这不起作用!?
感谢
制作一个测试用例。 – 2012-01-08 19:50:13
你在哪里试图获得'timeStampCleaned'变量?不在你粘贴的代码中。 – 2012-01-08 19:52:46
IF语句是有条件的,所以如果你第一次使用这个变量在你的IF语句中(即在那里定义),那么你必须确保它被实际调用。如果你的IF语句跳过它,当你稍后使用它时,它将是未定义的。 – 2012-01-08 19:53:12