<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.info.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.assert-options.php',
    1 => 'assert_options',
    2 => 'Set/get the various assert flags',
  ),
  'up' => 
  array (
    0 => 'ref.info.php',
    1 => 'PHP Options/Info Functions',
  ),
  'prev' => 
  array (
    0 => 'function.assert.php',
    1 => 'assert',
  ),
  'next' => 
  array (
    0 => 'function.cli-get-process-title.php',
    1 => 'cli_get_process_title',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/info/functions/assert-options.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.assert-options" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">assert_options</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">assert_options</span> &mdash; <span class="dc-title">Set/get the various assert flags</span></p>

 </div>

 <div id="function.assert-options-refsynopsisdiv">
  <div class="warning"><strong class="warning">Warning</strong><p class="simpara">This function has been
<em>DEPRECATED</em> as of PHP 8.3.0. Relying on this function
is highly discouraged.</p></div>
 </div>
 
 <div class="refsect1 description" id="refsect1-function.assert-options-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>assert_options</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$option</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   Set the various <span class="function"><a href="function.assert.php" class="function">assert()</a></span> control options or just query
   their current settings.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    The use of <span class="function"><strong>assert_options()</strong></span> is discouraged
    in favor of setting and getting the <var class="filename">php.ini</var> directives
    <a href="ini.core.php#ini.zend.assertions" class="link">zend.assertions</a> and
    <a href="info.configuration.php#ini.assert.exception" class="link">assert.exception</a> with
    <span class="function"><a href="function.ini-set.php" class="function">ini_set()</a></span> and <span class="function"><a href="function.ini-get.php" class="function">ini_get()</a></span>, respectively.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.assert-options-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">option</code></dt>
     <dd>
      <p class="para">
       <table class="doctable table">
        <caption><strong>Assert Options</strong></caption>
        
         <thead>
          <tr>
           <th>Option</th>
           <th>INI Setting</th>
           <th>Default value</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>ASSERT_ACTIVE</td>
           <td>assert.active</td>
           <td>1</td>
           <td>enable <span class="function"><a href="function.assert.php" class="function">assert()</a></span> evaluation</td>
          </tr>

          <tr>
           <td>ASSERT_EXCEPTION</td>
           <td>assert.exception</td>
           <td>1</td>
           <td>throws an <span class="classname"><a href="class.assertionerror.php" class="classname">AssertionError</a></span> for each failed assertions</td>
          </tr>

          <tr>
           <td>ASSERT_WARNING</td>
           <td>assert.warning</td>
           <td>1</td>
           <td>issue a PHP warning for each failed assertion</td>
          </tr>

          <tr>
           <td>ASSERT_BAIL</td>
           <td>assert.bail</td>
           <td>0</td>
           <td>terminate execution on failed assertions</td>
          </tr>

          <tr>
           <td>ASSERT_QUIET_EVAL</td>
           <td>assert.quiet_eval</td>
           <td>0</td>
           <td>
            disable error_reporting during assertion expression
            evaluation. Removed as of PHP 8.0.0.
           </td>
          </tr>

          <tr>
           <td>ASSERT_CALLBACK</td>
           <td>assert.callback</td>
           <td>(<strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>)</td>
           <td>Callback to call on failed assertions</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       An optional new value for the option.
      </p>
      <p class="para">
       The callback function set via <strong><code><a href="info.constants.php#constant.assert-callback">ASSERT_CALLBACK</a></code></strong> or
       <a href="info.configuration.php#ini.assert.callback" class="link">assert.callback</a>
       should have the following signature:
       <div class="methodsynopsis dc-description">
        <span class="methodname"><strong>assert_callback</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$file</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$line</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$assertion</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$description</code><span class="initializer"> = ?</span></span><br>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

       <dl>
        
         <dt><code class="parameter">file</code></dt>
         <dd>
          <span class="simpara">
           The file where <span class="function"><a href="function.assert.php" class="function">assert()</a></span> has been called.
          </span>
         </dd>
        
        
         <dt><code class="parameter">line</code></dt>
         <dd>
          <span class="simpara">
           The line where <span class="function"><a href="function.assert.php" class="function">assert()</a></span> has been called.
          </span>
         </dd>
        
        
         <dt><code class="parameter">assertion</code></dt>
         <dd>
          <span class="simpara">
           Prior to PHP 8.0.0, the assertion which has been passed to <span class="function"><a href="function.assert.php" class="function">assert()</a></span>,
           but only when the assertion is given as a string.
           (If the assertion is a boolean condition, this parameter will be an empty string.)
           As of PHP 8.0.0, this parameter is always <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
          </span>
         </dd>
        
        
         <dt><code class="parameter">description</code></dt>
         <dd>
          <span class="simpara">
           The description that has been passed to <span class="function"><a href="function.assert.php" class="function">assert()</a></span>.
          </span>
         </dd>
        
       </dl>
      </p>
     </dd>
    
   </dl>
   Passing an empty string as <code class="parameter">value</code> resets the assert callback.
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.assert-options-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the original setting of any option.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.assert-options-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   If <code class="parameter">option</code> is not a valid option a
   <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> is thrown.
  </p>
 </div>


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

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.3.0</td>
       <td>
        <span class="function"><strong>assert_option()</strong></span> is now deprecated.
       </td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        If <code class="parameter">option</code> is not a valid option,
        a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> is now thrown.
        Previously <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> was returned.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.assert-options-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>assert_options()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// This is our function to handle <br />// assert failures<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">assert_failure</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">, </span><span style="color: #0000BB">$line</span><span style="color: #007700">, </span><span style="color: #0000BB">$assertion</span><span style="color: #007700">, </span><span style="color: #0000BB">$message</span><span style="color: #007700">)<br />{<br />    echo </span><span style="color: #DD0000">"The assertion </span><span style="color: #0000BB">$assertion</span><span style="color: #DD0000"> in </span><span style="color: #0000BB">$file</span><span style="color: #DD0000"> on line </span><span style="color: #0000BB">$line</span><span style="color: #DD0000"> has failed: </span><span style="color: #0000BB">$message</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// This is our test function<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">test_assert</span><span style="color: #007700">(</span><span style="color: #0000BB">$parameter</span><span style="color: #007700">)<br />{<br />    </span><span style="color: #0000BB">assert</span><span style="color: #007700">(</span><span style="color: #0000BB">is_bool</span><span style="color: #007700">(</span><span style="color: #0000BB">$parameter</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #FF8000">// Set our assert options<br /></span><span style="color: #0000BB">assert_options</span><span style="color: #007700">(</span><span style="color: #0000BB">ASSERT_ACTIVE</span><span style="color: #007700">,   </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">assert_options</span><span style="color: #007700">(</span><span style="color: #0000BB">ASSERT_BAIL</span><span style="color: #007700">,     </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">assert_options</span><span style="color: #007700">(</span><span style="color: #0000BB">ASSERT_WARNING</span><span style="color: #007700">,  </span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">assert_options</span><span style="color: #007700">(</span><span style="color: #0000BB">ASSERT_CALLBACK</span><span style="color: #007700">, </span><span style="color: #DD0000">'assert_failure'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Make an assert that would fail<br /></span><span style="color: #0000BB">test_assert</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// This is never reached due to ASSERT_BAIL <br />// being true<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'Never reached'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-function.assert-options-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.assert.php" class="function" rel="rdfs-seeAlso">assert()</a> - Checks an assertion</span></li>
   </ul>
  </p>
 </div>


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