1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
<?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>
<refsynopsisdiv>
&warn.deprecated.function-8-3-0;
</refsynopsisdiv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>mixed</type><methodname>assert_options</methodname>
<methodparam><type>int</type><parameter>option</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>
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>option</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_EXCEPTION</entry>
<entry>assert.exception</entry>
<entry>1</entry>
<entry>throws an <classname>AssertionError</classname> for each failed assertions</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. Removed as of PHP 8.0.0.
</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
<link linkend="ini.assert.callback">assert.callback</link>
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 class="union"><type>string</type><type>null</type></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>
Prior to PHP 8.0.0, the assertion which has been passed to <function>assert</function>,
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 &null;.
</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.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
If <parameter>option</parameter> is not a valid option a
<classname>ValueError</classname> is thrown.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
<function>assert_option</function> is now deprecated.
</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
If <parameter>option</parameter> is not a valid option,
a <classname>ValueError</classname> is now thrown.
Previously &false; was returned.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</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
-->
|