Jump to content
Larry Ullman's Book Forums

Script 8.1 - Functions only defined in conditional statements


Recommended Posts

In Script 8.1, some of the functions seem not to be directly defined. For example, the write function is: function write($data) { if (@!fwrite($this->_fp, $data . "\n")) {throw new Exception(...); }

It seems like it should say positively to execute "fwrite($this->_fp, $data)", but instead it just says if it doesn't do this, then throw an exception. It seems like the conditional would always be true since the script never told the computer to do it. What am I missing?

Link to comment
Share on other sites

Ah, sorry for the confusion. By putting fwrite() as the condition, it'll always be executed when the write() method is called. The condition then reacts based upon the result of the fwrite() call. Put another way: the fwrite() call is not being conditionally called; it's always called. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...