downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.trigger-error.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.errorfunc.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.trigger-error.php',
   
1 => 'trigger_error',
  ),
 
'up' =>
  array (
   
0 => 'ref.errorfunc.php',
   
1 => 'Error Handling Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.set-exception-handler.php',
   
1 => 'set_exception_handler',
  ),
 
'next' =>
  array (
   
0 => 'function.user-error.php',
   
1 => 'user_error',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.trigger-error" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">trigger_error</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5)</p><p class="refpurpose"><span class="refname">trigger_error</span> &mdash; <span class="dc-title">Generates a user-level error/warning/notice message</span></p>

 </div>

 <a name="function.trigger-error.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><b>trigger_error</b></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$error_msg</tt></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$error_type</tt><span class="initializer"> = E_USER_NOTICE</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   Used to trigger a user error condition, it can be used by in conjunction
   with the built-in error handler, or with a user defined function that has
   been set as the new error handler
   (<a href="function.set-error-handler.php" class="function">set_error_handler()</a>).
  </p>
  <p class="para">
   This function is useful when you need to generate a particular response to
   an exception at runtime.
  </p>
 </div>


 <a name="function.trigger-error.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">error_msg</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The designated error message for this error. It&#039;s limited to 1024
       characters in length. Any additional characters beyond 1024 will be
       truncated.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">error_type</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The designated error type for this error. It only works with the E_USER
       family of constants, and will default to <b><tt class="constant">E_USER_NOTICE</tt></b>.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.trigger-error.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   This function returns <b><tt class="constant">FALSE</tt></b> if wrong <i><tt class="parameter">error_type</tt></i>
 is
   specified, <b><tt class="constant">TRUE</tt></b> otherwise.
  </p>
 </div>


 <a name="function.trigger-error.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>trigger_error()</b> example</b></p>
    <div class="example-contents para"><p>
     See <a href="function.set-error-handler.php" class="function">set_error_handler()</a> for a more extensive example.
    </p></div>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">assert</span><span style="color: #007700">(</span><span style="color: #0000BB">$divisor&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"Cannot&nbsp;divide&nbsp;by&nbsp;zero"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div>


 <a name="function.trigger-error.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.error-reporting.php" class="function" rel="rdfs-seeAlso">error_reporting()</a> - Sets which PHP errors are reported</li>
    <li class="member"><a href="function.set-error-handler.php" class="function" rel="rdfs-seeAlso">set_error_handler()</a> - Sets a user-defined error handler function</li>
    <li class="member"><a href="function.restore-error-handler.php" class="function" rel="rdfs-seeAlso">restore_error_handler()</a> - Restores the previous error handler function</li>
    <li class="member">The <a href="errorfunc.constants.php" class="link">error level constants</a></li>
   </ul><p>
  </p>
 </div>

</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites