php-doc-en/reference/info/functions/assert-options.xml
Andrey Gromov bbd4f6a100 Typo
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@349184 c90b9560-bf6c-de11-be94-00142212c4b1
2020-02-09 08:47:39 +00:00

226 lines
6.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.assert-options" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>assert_options</refname>
<refpurpose>Set/get the various assert flags</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>mixed</type><methodname>assert_options</methodname>
<methodparam><type>int</type><parameter>what</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>value</parameter></methodparam>
</methodsynopsis>
<para>
Set the various <function>assert</function> control options or just query
their current settings.
</para>
<note>
<simpara>
As of PHP 7.0.0, the use of <function>assert_options</function> is discouraged
in favor of setting and getting the &php.ini; directives
<link linkend="ini.zend.assertions">zend.assertions</link> and
<link linkend="ini.assert.exception">assert.exception</link> with
<function>ini_set</function> and <function>ini_get</function>, respectively.
</simpara>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>what</parameter></term>
<listitem>
<para>
<table>
<title>Assert Options</title>
<tgroup cols="4">
<thead>
<row>
<entry>Option</entry>
<entry>INI Setting</entry>
<entry>Default value</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>ASSERT_ACTIVE</entry>
<entry>assert.active</entry>
<entry>1</entry>
<entry>enable <function>assert</function> evaluation</entry>
</row>
<row>
<entry>ASSERT_WARNING</entry>
<entry>assert.warning</entry>
<entry>1</entry>
<entry>issue a PHP warning for each failed assertion</entry>
</row>
<row>
<entry>ASSERT_BAIL</entry>
<entry>assert.bail</entry>
<entry>0</entry>
<entry>terminate execution on failed assertions</entry>
</row>
<row>
<entry>ASSERT_QUIET_EVAL</entry>
<entry>assert.quiet_eval</entry>
<entry>0</entry>
<entry>
disable error_reporting during assertion expression
evaluation
</entry>
</row>
<row>
<entry>ASSERT_CALLBACK</entry>
<entry>assert.callback</entry>
<entry>(&null;)</entry>
<entry>Callback to call on failed assertions</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>value</parameter></term>
<listitem>
<para>
An optional new value for the option.
</para>
<para>
The callback function set via <constant>ASSERT_CALLBACK</constant> or assert.callback should
have the following signature:
<methodsynopsis role="procedural">
<type>void</type><methodname>assert_callback</methodname>
<methodparam><type>string</type><parameter>file</parameter></methodparam>
<methodparam><type>int</type><parameter>line</parameter></methodparam>
<methodparam><type>string</type><parameter>assertion</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>description</parameter></methodparam>
</methodsynopsis>
<variablelist>
<varlistentry>
<term><parameter>file</parameter></term>
<listitem>
<simpara>
The file where <function>assert</function> has been called.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>line</parameter></term>
<listitem>
<simpara>
The line where <function>assert</function> has been called.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>assertion</parameter></term>
<listitem>
<simpara>
The assertion that has been passed to <function>assert</function>,
converted to a string.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>description</parameter></term>
<listitem>
<simpara>
The description that has been passed to <function>assert</function>.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
Passing an empty string as <parameter>value</parameter> resets the assert callback.
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the original setting of any option or &false; on errors.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>assert_options</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// This is our function to handle
// assert failures
function assert_failure($file, $line, $assertion, $message)
{
echo "The assertion $assertion in $file on line $line has failed: $message";
}
// This is our test function
function test_assert($parameter)
{
assert(is_bool($parameter));
}
// Set our assert options
assert_options(ASSERT_ACTIVE, true);
assert_options(ASSERT_BAIL, true);
assert_options(ASSERT_WARNING, false);
assert_options(ASSERT_CALLBACK, 'assert_failure');
// Make an assert that would fail
test_assert(1);
// This is never reached due to ASSERT_BAIL
// being true
echo 'Never reached';
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>assert</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->