title: Preventing PHP Warnings on LDAP Functions
body: <p>Currently I am using the <code>ldap_*</code> functions to handle authentication for one of my web applications. I have logic that is able to check if the login is valid which works fine, however when a user enters an invalid username/password combination <code>ldap_bind()</code> produces a warning which I would like to avoid if possible. At the moment I am suppressing this error with the <code>@</code> operator but I am curious if there is a better way to block warnings from <code>ldap_*</code> without turning off warnings in PHP completely or suppressing them.</p>
  <p>The warning is</p>
  <blockquote>
  <p>A PHP Error was encountered</p>
  <p>Severity: Warning</p>
  <p>Message: ldap_bind() [function.ldap-bind]: Unable to bind to server: Invalid credentials</p>
  <p>Filename: libraries/userauth.php</p>
  <p>Line Number: 75</p>
  </blockquote>
  <p>My current code is as follows:</p>
  <pre><code>$uid = &quot;uid=&quot;.$username;
  $ldapUser = $uid.&quot;,ou=***,dc=***,dc=***&quot;;
  $ds = ldap_connect( $this-&gt;ldapURL ); 
  $lb = @ldap_bind( $ds, $ldapUser, $password );
  $sr = ldap_search( $ds, $this-&gt;ldapBaseDN, $uid );
  $info = ldap_get_entries( $ds, $sr );
  </code></pre>
  <p>Is there any way to prevent this warning without turning of PHP warnings altogether or suppressing it?</p>