<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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',
    2 => 'Generates a user-level error/warning/notice message',
  ),
  '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',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/errorfunc/functions/trigger-error.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<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, PHP 7, PHP 8)</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>

 <div class="refsect1 description" id="refsect1-function.trigger-error-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>trigger_error</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$message</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$error_level</code><span class="initializer"> = <strong><code><a href="errorfunc.constants.php#constant.e-user-notice">E_USER_NOTICE</a></code></strong></span></span>): <span class="type"><a href="language.types.singleton.php" class="type true">true</a></span></div>

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


 <div class="refsect1 parameters" id="refsect1-function.trigger-error-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">message</code></dt>
     <dd>
      <p class="para">
       The designated error message for this error. It&#039;s limited to 1024 
       bytes in length. Any additional characters beyond 1024 bytes will be 
       truncated.
      </p>
     </dd>
    
    
     <dt><code class="parameter">error_level</code></dt>
     <dd>
      <p class="para">
       The designated error type for this error. It only works with the <strong><code><a href="errorfunc.constants.php#constant.e-user-error">E_USER_<span class="replaceable">*</span></a></code></strong>
       family of constants, and will default to <strong><code><a href="errorfunc.constants.php#constant.e-user-notice">E_USER_NOTICE</a></code></strong>.
      </p>
      <div class="warning"><strong class="warning">Warning</strong>
       <p class="simpara">
        Passing <strong><code><a href="errorfunc.constants.php#constant.e-user-error">E_USER_ERROR</a></code></strong> as the
        <code class="parameter">error_level</code> is now deprecated.
        Throw an <span class="exceptionname"><a href="class.exception.php" class="exceptionname">Exception</a></span> or
        call <span class="function"><a href="function.exit.php" class="function">exit()</a></span> instead.
       </p>
      </div>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.trigger-error-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Always returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.trigger-error-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   This function throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> if
   <code class="parameter">error_level</code> is not one of
   <strong><code><a href="errorfunc.constants.php#constant.e-user-error">E_USER_ERROR</a></code></strong>, <strong><code><a href="errorfunc.constants.php#constant.e-user-warning">E_USER_WARNING</a></code></strong>,
   <strong><code><a href="errorfunc.constants.php#constant.e-user-notice">E_USER_NOTICE</a></code></strong>, <strong><code><a href="errorfunc.constants.php#constant.e-user-deprecated">E_USER_DEPRECATED</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.trigger-error-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.4.0</td>
      <td>
       Passing <strong><code><a href="errorfunc.constants.php#constant.e-user-error">E_USER_ERROR</a></code></strong> as the
       <code class="parameter">error_level</code> is now deprecated.
       Throw an <span class="exceptionname"><a href="class.exception.php" class="exceptionname">Exception</a></span> or
       call <span class="function"><a href="function.exit.php" class="function">exit()</a></span> instead.
      </td>
     </tr>

     <tr>
      <td>8.4.0</td>
      <td>
       The function now has a return type of <span class="type"><a href="language.types.singleton.php" class="type true">true</a></span>
       instead of <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       The function now throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> if an invalid
       <code class="parameter">error_level</code> is specified. Previously, it returned <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.trigger-error-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>trigger_error()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     See <span class="function"><a href="function.set-error-handler.php" class="function">set_error_handler()</a></span> for a more extensive example.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$password </span><span style="color: #007700">= </span><span style="color: #0000BB">$_POST</span><span style="color: #007700">[</span><span style="color: #DD0000">'password'</span><span style="color: #007700">] ?? </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br />if (</span><span style="color: #0000BB">$password </span><span style="color: #007700">=== </span><span style="color: #DD0000">''</span><span style="color: #007700">) {<br />  </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"Using an empty password is unsafe"</span><span style="color: #007700">, </span><span style="color: #0000BB">E_USER_WARNING</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">$hash </span><span style="color: #007700">= </span><span style="color: #0000BB">password_hash</span><span style="color: #007700">(</span><span style="color: #0000BB">$password</span><span style="color: #007700">, </span><span style="color: #0000BB">PASSWORD_DEFAULT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.trigger-error-notes">
  <h3 class="title">Notes</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
     HTML entities in <code class="parameter">message</code> are not
     escaped. Use <span class="function"><a href="function.htmlentities.php" class="function">htmlentities()</a></span> on the message if
     the error is to be displayed in a browser.
   </p>
  </div>
 </div>


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

</div><?php manual_footer($setup); ?>