blues
blues

Reputation: 5195

How can php code wrapped in if(false) produce an error?

I have a situation where code that is wrapped in if(false) { /* code here */ } stops a page from loading when it is uncommented. Browser says "the server reset the connection". The environment is:

Any pointers where even to start looking for the reason this happens are welcome!

Edit: the actual code

// 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

Upvotes: 1

Views: 36

Answers (1)

mopo922
mopo922

Reputation: 6381

In PHP < 5.5, empty() can only accept a variable as its parameter. This minor refactor will make your code a little cleaner anyways:

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']); 
        }
    }
}

Upvotes: 1

Related Questions