title: Should I be using assert in my PHP code?
body: <p>A coworker has added the <a href="http://php.net/assert">assert</a> command a few times within our libraries in places where I would have used an if statement and thrown an exception. (I had never even heard of assert before this.) Here is an example of how he used it:</p>
  
  <pre><code>assert('isset($this-&gt;records); /* Records must be set before this is called. */');
  </code></pre>
  
  <p>I would have done:</p>
  
  <pre><code>if (!isset($this-&gt;records)) {
      throw new Exception('Records must be set before this is called');
  }
  </code></pre>
  
  <p>From reading <a href="http://php.net/assert">the PHP docs on assert</a>, it looks like it's recommended that you make sure assert is active and add a handler before using assert. I can't find a place where he's done this.</p>
  
  <p>So, my question is, is using assert a good idea given the above and should I be using it more often instead of if's and exceptions?</p>
  
  <p>Another note, we are planning to use these libraries on a variety of projects and servers, including projects that we may not even be part of (the libraries are open source). Does this make any difference in using assert?</p>