reference/info/functions/assert-options.xml
ada1d79de35239334b68d0120b011530e31244ff
...
...
@@ -6,17 +6,30 @@
6
6
<refpurpose>Set/get the various assert flags</refpurpose>
7
7
</refnamediv>
8
8

9
+
<refsynopsisdiv>
10
+
&warn.deprecated.function-8-3-0;
11
+
</refsynopsisdiv>
12
+
9
13
<refsect1 role="description">
10
14
&reftitle.description;
11
15
<methodsynopsis>
12
16
<type>mixed</type><methodname>assert_options</methodname>
13
-
<methodparam><type>int</type><parameter>what</parameter></methodparam>
17
+
<methodparam><type>int</type><parameter>option</parameter></methodparam>
14
18
<methodparam choice="opt"><type>mixed</type><parameter>value</parameter></methodparam>
15
19
</methodsynopsis>
16
20
<para>
17
21
Set the various <function>assert</function> control options or just query
18
22
their current settings.
19
23
</para>
24
+
<note>
25
+
<simpara>
26
+
The use of <function>assert_options</function> is discouraged
27
+
in favor of setting and getting the &php.ini; directives
28
+
<link linkend="ini.zend.assertions">zend.assertions</link> and
29
+
<link linkend="ini.assert.exception">assert.exception</link> with
30
+
<function>ini_set</function> and <function>ini_get</function>, respectively.
31
+
</simpara>
32
+
</note>
20
33
</refsect1>
21
34

22
35
<refsect1 role="parameters">
...
...
@@ -24,7 +37,7 @@
24
37
<para>
25
38
<variablelist>
26
39
<varlistentry>
27
-
<term><parameter>what</parameter></term>
40
+
<term><parameter>option</parameter></term>
28
41
<listitem>
29
42
<para>
30
43
<table>
...
...
@@ -46,6 +59,12 @@
46
59
<entry>enable <function>assert</function> evaluation</entry>
47
60
</row>
48
61
<row>
62
+
<entry>ASSERT_EXCEPTION</entry>
63
+
<entry>assert.exception</entry>
64
+
<entry>1</entry>
65
+
<entry>throws an <classname>AssertionError</classname> for each failed assertions</entry>
66
+
</row>
67
+
<row>
49
68
<entry>ASSERT_WARNING</entry>
50
69
<entry>assert.warning</entry>
51
70
<entry>1</entry>
...
...
@@ -63,7 +82,7 @@
63
82
<entry>0</entry>
64
83
<entry>
65
84
disable error_reporting during assertion expression
66
-
evaluation
85
+
evaluation. Removed as of PHP 8.0.0.
67
86
</entry>
68
87
</row>
69
88
<row>
...
...
@@ -84,16 +103,106 @@
84
103
<para>
85
104
An optional new value for the option.
86
105
</para>
106
+
<para>
107
+
The callback function set via <constant>ASSERT_CALLBACK</constant> or
108
+
<link linkend="ini.assert.callback">assert.callback</link>
109
+
should have the following signature:
110
+
<methodsynopsis role="procedural">
111
+
<type>void</type><methodname>assert_callback</methodname>
112
+
<methodparam><type>string</type><parameter>file</parameter></methodparam>
113
+
<methodparam><type>int</type><parameter>line</parameter></methodparam>
114
+
<methodparam><type class="union"><type>string</type><type>null</type></type><parameter>assertion</parameter></methodparam>
115
+
<methodparam choice="opt"><type>string</type><parameter>description</parameter></methodparam>
116
+
</methodsynopsis>
117
+
<variablelist>
118
+
<varlistentry>
119
+
<term><parameter>file</parameter></term>
120
+
<listitem>
121
+
<simpara>
122
+
The file where <function>assert</function> has been called.
123
+
</simpara>
124
+
</listitem>
125
+
</varlistentry>
126
+
<varlistentry>
127
+
<term><parameter>line</parameter></term>
128
+
<listitem>
129
+
<simpara>
130
+
The line where <function>assert</function> has been called.
131
+
</simpara>
132
+
</listitem>
133
+
</varlistentry>
134
+
<varlistentry>
135
+
<term><parameter>assertion</parameter></term>
136
+
<listitem>
137
+
<simpara>
138
+
Prior to PHP 8.0.0, the assertion which has been passed to <function>assert</function>,
139
+
but only when the assertion is given as a string.
140
+
(If the assertion is a boolean condition, this parameter will be an empty string.)
141
+
As of PHP 8.0.0, this parameter is always &null;.
142
+
</simpara>
143
+
</listitem>
144
+
</varlistentry>
145
+
<varlistentry>
146
+
<term><parameter>description</parameter></term>
147
+
<listitem>
148
+
<simpara>
149
+
The description that has been passed to <function>assert</function>.
150
+
</simpara>
151
+
</listitem>
152
+
</varlistentry>
153
+
</variablelist>
154
+
</para>
87
155
</listitem>
88
156
</varlistentry>
89
157
</variablelist>
158
+
Passing an empty string as <parameter>value</parameter> resets the assert callback.
90
159
</para>
91
160
</refsect1>
92
161

93
162
<refsect1 role="returnvalues">
94
163
&reftitle.returnvalues;
95
164
<para>
96
-
Returns the original setting of any option or &false; on errors.
165
+
Returns the original setting of any option.
166
+
</para>
167
+
</refsect1>
168
+

169
+
<refsect1 role="errors">
170
+
&reftitle.errors;
171
+
<para>
172
+
If <parameter>option</parameter> is not a valid option a
173
+
<classname>ValueError</classname> is thrown.
174
+
</para>
175
+
</refsect1>
176
+

177
+
<refsect1 role="changelog">
178
+
&reftitle.changelog;
179
+
<para>
180
+
<informaltable>
181
+
<tgroup cols="2">
182
+
<thead>
183
+
<row>
184
+
<entry>&Version;</entry>
185
+
<entry>&Description;</entry>
186
+
</row>
187
+
</thead>
188
+
<tbody>
189
+
<row>
190
+
<entry>8.3.0</entry>
191
+
<entry>
192
+
<function>assert_option</function> is now deprecated.
193
+
</entry>
194
+
</row>
195
+
<row>
196
+
<entry>8.0.0</entry>
197
+
<entry>
198
+
If <parameter>option</parameter> is not a valid option,
199
+
a <classname>ValueError</classname> is now thrown.
200
+
Previously &false; was returned.
201
+
</entry>
202
+
</row>
203
+
</tbody>
204
+
</tgroup>
205
+
</informaltable>
97
206
</para>
98
207
</refsect1>
99
208

...
...
@@ -107,9 +216,9 @@
107
216
<?php
108
217
// This is our function to handle
109
218
// assert failures
110
-
function assert_failure()
219
+
function assert_failure($file, $line, $assertion, $message)
111
220
{
112
-
echo 'Assert failed';
221
+
echo "The assertion $assertion in $file on line $line has failed: $message";
113
222
}
114
223

115
224
// This is our test function
116
225