title: Test if a variable is serializable
body: <p>I'm looking for an elegant way of testing if a variable is serializable. For example <code>array( function() {} )</code> will fail to serialize.</p>
  
  <p>I'm currently using the code below, but it seems to be a rather non-optimal way of doing it.</p>
  
  <pre><code>function isSerializable( $var )
  {
      try {
          serialize( $var );
          return TRUE;
      } catch( Exception $e ) {
          return FALSE;
      }
  }
  
  var_dump( isSerializable( array() ) );                // bool(true)
  var_dump( isSerializable( function() {} ) );          // bool(false)
  var_dump( isSerializable( array( function() {} ) ) ); // bool(false)
  </code></pre>