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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...