我遇到这样一种情况,即包装在if(false) { /* code here */ }
中的代码在取消注释页面时会阻止页面加载。浏览器显示"服务器重置连接"。环境是:
- 蛋糕PHP: 2.5.2
- PHP: 5.5.9-1ubuntu4.14
- Apache/2.2.22 (Debian)
欢迎任何甚至开始寻找发生这种情况的原因的指针!
编辑:实际代码
// code above
exit();
if(false) {
/*
foreach($all_item_types as $ait) {
$id = $ait['ItemType']['id'];
$ItemSubtypeVersionView->find('first', array('conditions' => array('item_type_id'=>$id)));
if(empty($ItemSubtypeVersionView->find('first', array('conditions' => array('item_type_id'=>$id))))) {
$empty_file_types[$id]= array('n'=>$ait['ItemType']['name']);
}
}
*/
}
// code below
在 PHP <5.5 中,empty()
只能接受变量作为其参数。无论如何,这个小的重构都会让你的代码更干净一些:
if (false) {
foreach ($all_item_types as $ait) {
$id = $ait['ItemType']['id'];
$result = $ItemSubtypeVersionView->find('first', array('conditions' => array('item_type_id' => $id)));
if (empty($result)) {
$empty_file_types[$id]= array('n' => $ait['ItemType']['name']);
}
}
}