title: use of assertions for type checking in php?
body: <p>I do some checking of arguments in my classes in php using exception-throwing functions. I have functions that do a basic check ( <code>===</code>, <code>in_array</code> etc ) and throw an exception on false. So I can do <code>assertNumeric($argument, "\$argument is not numeric.");</code> instead of</p>
  
  <pre><code>if ( ! is_numeric($argument) ) {
      throw new Exception("\$argument is not numeric.");
  }
  </code></pre>
  
  <p>Saves some typing</p>
  
  <p>I was reading in the comments of the <a href="http://php.net/manual/en/function.assert.php" rel="nofollow noreferrer">php manual page on assert()</a> that</p>
  
  <blockquote>
    <p>As noted on Wikipedia - "assertions
    are primarily a development tool, they
    are often disabled when a program is
    released to the public." and
    "Assertions should be used to document
    logically impossible situations and
    discover programming errors— if the
    'impossible' occurs, then something
    fundamental is clearly wrong. This is
    distinct from error handling: most
    error conditions are possible,
    although some may be extremely
    unlikely to occur in practice. Using
    assertions as a general-purpose error
    handling mechanism is usually unwise:
    assertions do not allow for graceful
    recovery from errors, and an assertion
    failure will often halt the program's
    execution abruptly. Assertions also do
    not display a user-friendly error
    message."</p>
    
    <p>This means that the advice given by
    "gk at proliberty dot com" to force
    assertions to be enabled, even when
    they have been disabled manually, goes
    against best practices of only using
    them as a development tool</p>
  </blockquote>
  
  <p>So, am I 'doing it wrong'? What other/better ways of doing this are there?</p>