title: How to set custom error handler in Codeigniter to Email errors
body: <p>I'm fairly new to PHP and the setting of custom error handlers, but I have some code which works fine outside of CI but I can't work out how to integrate this into a CI Controller. I get an error "Message: Undefined property: Errors::$my_error_handler"</p>
  
  <p>My Controller is:</p>
  
  <pre><code>&lt;?php
  class Errors extends CI_Controller {
  
  
      public function __construct()
      {
          parent::__construct();
  
      }
  
      function my_error_handler($number, $message, $file, $line, $vars)
      {
          $email = "
              &lt;p&gt;An error ($number) occurred on line
              &lt;strong&gt;$line&lt;/strong&gt; and in the &lt;strong&gt;file: $file.&lt;/strong&gt;
              &lt;p&gt; $message &lt;/p&gt;";
  
          $email .= "&lt;pre&gt;" . print_r($vars, 1) . "&lt;/pre&gt;";
  
          $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  
          // Email the error to someone...
          error_log($email, 1, 'name@domain.com', $headers);
  
          // Make sure that you decide how to respond to errors (on the user's side)
          // Either echo an error message, or kill the entire project. Up to you...
          // The code below ensures that we only "die" if the error was more than
          // just a NOTICE.
          if ( ($number !== E_NOTICE) &amp;&amp; ($number &lt; 2048) ) {
              die("There was an error. Please try again later.");
          }
      }
  
  
      function test()
      {
          // We should use our custom function to handle errors.
          set_error_handler($this-&gt;my_error_handler);
  
          // Trigger an error... (var doesn't exist)
          echo $somevarthatdoesnotexist;
  
      }
  
  }
  ?&gt;
  </code></pre>
  
  <p>If there is a better way to email error messages using CI please let me know.</p>