reference/info/functions/assert.xml
27dcb487a7e9c0f04559522a6d2aacf860d622cd
...
...
@@ -3,118 +3,60 @@
3
3
<refentry xml:id="function.assert" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>assert</refname>
6
-
<refpurpose>Checks if assertion is &false;</refpurpose>
6
+
<refpurpose>Checks an assertion</refpurpose>
7
7
</refnamediv>
8
8

9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
-
<para>PHP 5</para>
12
11
<methodsynopsis>
13
12
<type>bool</type><methodname>assert</methodname>
14
13
<methodparam><type>mixed</type><parameter>assertion</parameter></methodparam>
15
-
<methodparam choice="opt"><type>string</type><parameter>description</parameter></methodparam>
16
-
</methodsynopsis>
17
-
<para>PHP 7</para>
18
-
<methodsynopsis>
19
-
<type>bool</type><methodname>assert</methodname>
20
-
<methodparam><type>mixed</type><parameter>assertion</parameter></methodparam>
21
-
<methodparam choice="opt"><type>Throwable</type><parameter>exception</parameter></methodparam>
14
+
<methodparam choice="opt"><type class="union"><type>Throwable</type><type>string</type><type>null</type></type><parameter>description</parameter><initializer>&null;</initializer></methodparam>
22
15
</methodsynopsis>
23
16
<para>
24
-
<function>assert</function> will check the given
25
-
<parameter>assertion</parameter> and take appropriate action if
26
-
its result is &false;.
17
+
<function>assert</function>
18
+
allows for the definition of expectations: assertions that take effect
19
+
in development and testing environments, but are optimised away to have
20
+
zero cost in production.
21
+
</para>
22
+
<para>
23
+
Assertions should be used as a debugging feature only.
24
+
One use case for them is to act as sanity-checks for preconditions
25
+
that should always be &true; and that if they aren't upheld this indicates
26
+
some programming errors.
27
+
Another use case is to ensure the presence of certain features like
28
+
extension functions or certain system limits and features.
29
+
</para>
30
+
<para>
31
+
As assertions can be configured to be eliminated, they should
32
+
<emphasis>not</emphasis> be used for normal runtime operations like
33
+
input parameter checks. As a rule of thumb code should behave as expected
34
+
even if assertion checking is deactivated.
27
35
</para>
28
-
<refsect2>
29
-
<title>Traditional assertions (PHP 5 and 7)</title>
30
-
<para>
31
-
If the <parameter>assertion</parameter> is given as a string it
32
-
will be evaluated as PHP code by <function>assert</function>.
33
-
The advantages of a string <parameter>assertion</parameter> are
34
-
less overhead when assertion checking is off and messages
35
-
containing the <parameter>assertion</parameter> expression when
36
-
an assertion fails. This means that if you pass a boolean condition
37
-
as <parameter>assertion</parameter> this condition will not show up as
38
-
parameter to the assertion function which you may have defined with the
39
-
<function>assert_options</function> function, the condition is converted
40
-
to a string before calling that handler function, and the boolean &false;
41
-
is converted as the empty string.
42
-
</para>
43
-
<para>
44
-
Assertions should be used as a debugging feature only. You may
45
-
use them for sanity-checks that test for conditions that should
46
-
always be &true; and that indicate some programming errors if not
47
-
or to check for the presence of certain features like extension
48
-
functions or certain system limits and features.
49
-
</para>
50
-
<para>
51
-
Assertions should not be used for normal runtime operations like
52
-
input parameter checks. As a rule of thumb your code should
53
-
always be able to work correctly if assertion checking is not
54
-
activated.
55
-
</para>
56
-
<para>
57
-
The behavior of <function>assert</function> may be configured by
58
-
<function>assert_options</function> or by .ini-settings described
59
-
in that functions manual page.
60
-
</para>
61
-
<para>
62
-
The <function>assert_options</function> function and/or
63
-
<constant>ASSERT_CALLBACK</constant> configuration directive allow a
64
-
callback function to be set to handle failed assertions.
65
-
</para>
66
-
<para>
67
-
<function>assert</function> callbacks are particularly useful for
68
-
building automated test suites because they allow you to easily
69
-
capture the code passed to the assertion, along with information
70
-
on where the assertion was made. While this information can be
71
-
captured via other methods, using assertions makes it much faster
72
-
and easier!
73
-
</para>
74
-
<para>
75
-
The callback function should accept three arguments. The first
76
-
argument will contain the file the assertion failed in. The
77
-
second argument will contain the line the assertion failed on and
78
-
the third argument will contain the expression that failed (if
79
-
any &#x2014; literal values such as 1 or "two" will not be passed via
80
-
this argument). Users of PHP 5.4.8 and later may also provide a fourth
81
-
optional argument, which will contain the
82
-
<parameter>description</parameter> given to <function>assert</function>, if
83
-
it was set.
84
-
</para>
85
-
</refsect2>
86
-
<refsect2 xml:id="function.assert.expectations">
87
-
<title>Expectations (PHP 7 only)</title>
88
-
<para>
89
-
<function>assert</function> is a language construct in PHP 7, allowing for
90
-
the definition of expectations: assertions that take effect in development
91
-
and testing environments, but are optimised away to have zero cost in
92
-
production.
93
-
</para>
94
-
<para>
95
-
While <function>assert_options</function> can still be used to control
96
-
behaviour as described above for backward compatibility reasons, PHP 7
97
-
only code should use the two new configuration directives to control
98
-
the behaviour of <function>assert</function> and not call
99
-
<function>assert_options</function>.
100
-
</para>
36
+
<para>
37
+
<function>assert</function> will check that the expectation given in
38
+
<parameter>assertion</parameter> holds.
39
+
If not, and thus the result is &false;, it will take the appropriate action
40
+
depending on how <function>assert</function> was configured.
41
+
</para>
42
+

43
+
<para>
44
+
The behaviour of <function>assert</function> is dictated by the
45
+
following INI settings:
101
46
<table>
102
-
<title>
103
-
PHP 7 configuration directives for <function>assert</function>
104
-
</title>
105
-
<tgroup cols="3">
47
+
<title>Assert &ConfigureOptions;</title>
48
+
<tgroup cols="4">
106
49
<thead>
107
50
<row>
108
-
<entry>Directive</entry>
109
-
<entry>Default value</entry>
110
-
<entry>Possible values</entry>
51
+
<entry>&Name;</entry>
52
+
<entry>&Default;</entry>
53
+
<entry>&Description;</entry>
54
+
<entry>&Changelog;</entry>
111
55
</row>
112
56
</thead>
113
57
<tbody>
114
58
<row>
115
-
<entry>
116
-
<link linkend="ini.zend.assertions">zend.assertions</link>
117
-
</entry>
59
+
<entry><link linkend="ini.zend.assertions">zend.assertions</link></entry>
118
60
<entry><literal>1</literal></entry>
119
61
<entry>
120
62
<simplelist>
...
...
@@ -130,33 +72,90 @@
130
72
</member>
131
73
</simplelist>
132
74
</entry>
75
+
<entry/>
133
76
</row>
134
77
<row>
78
+
<entry><link linkend="ini.assert.active">assert.active</link></entry>
79
+
<entry>&true;</entry>
135
80
<entry>
81
+
If &false;, <function>assert</function> does not check the expectation
82
+
and returns &true;, unconditionally.
83
+
</entry>
84
+
<entry>
85
+
Deprecated as of PHP 8.3.0.
86
+
</entry>
87
+
</row>
88
+
<row>
89
+
<entry><link linkend="ini.assert.callback">assert.callback</link></entry>
90
+
<entry>&null;</entry>
91
+
<entry>
92
+
<para>
93
+
A user defined function to call when an assertion fails.
94
+
It's signature should be:
95
+
<methodsynopsis role="procedural">
96
+
<type>void</type><methodname>assert_callback</methodname>
97
+
<methodparam><type>string</type><parameter>file</parameter></methodparam>
98
+
<methodparam><type>int</type><parameter>line</parameter></methodparam>
99
+
<methodparam><type>null</type><parameter>assertion</parameter></methodparam>
100
+
<methodparam choice="opt"><type>string</type><parameter>description</parameter></methodparam>
101
+
</methodsynopsis>
102
+
</para>
103
+
</entry>
104
+
<entry>
105
+
<para>
106
+
Prior to PHP 8.0.0, the signature of the callback should be:
107
+
<methodsynopsis role="procedural">
108
+
<type>void</type><methodname>assert_callback</methodname>
109
+
<methodparam><type>string</type><parameter>file</parameter></methodparam>
110
+
<methodparam><type>int</type><parameter>line</parameter></methodparam>
111
+
<methodparam><type>string</type><parameter>assertion</parameter></methodparam>
112
+
<methodparam choice="opt"><type>string</type><parameter>description</parameter></methodparam>
113
+
</methodsynopsis>
114
+
</para>
115
+
<simpara>
116
+
Deprecated as of PHP 8.3.0.
117
+
</simpara>
118
+
</entry>
119
+
</row>
120
+
<row>
121
+
<entry><link linkend="ini.assert.exception">assert.exception</link></entry>
122
+
<entry>&true;</entry>
123
+
<entry>
124
+
If &true; will throw an <classname>AssertionError</classname> if the
125
+
expectation isn't upheld.
126
+
</entry>
127
+
<entry>
128
+
Deprecated as of PHP 8.3.0.
129
+
</entry>
130
+
</row>
131
+
<row>
132
+
<entry><link linkend="ini.assert.bail">assert.bail</link></entry>
133
+
<entry>&false;</entry>
134
+
<entry>
135
+
If &true; will abort execution of the PHP script if the
136
+
expectation isn't upheld.
137
+
</entry>
138
+
<entry>
139
+
Deprecated as of PHP 8.3.0.
140
+
</entry>
141
+
</row>
142
+
<row>
143
+
<entry><link linkend="ini.assert.warning">assert.warning</link></entry>
144
+
<entry>&true;</entry>
145
+
<entry>
146
+
If &true;, will emit an <constant>E_WARNING</constant> if the
147
+
expectation isn't upheld. This INI setting is ineffective if
136
148
<link linkend="ini.assert.exception">assert.exception</link>
149
+
is enabled.
137
150
</entry>
138
-
<entry><literal>0</literal></entry>
139
151
<entry>
140
-
<simplelist>
141
-
<member>
142
-
<literal>1</literal>: throw when the assertion fails, either by
143
-
throwing the object provided as the <parameter>exception</parameter>
144
-
or by throwing a new <classname>AssertionError</classname> object if
145
-
<parameter>exception</parameter> wasn't provided
146
-
</member>
147
-
<member>
148
-
<literal>0</literal>: use or generate a
149
-
<classname>Throwable</classname> as described above, but only
150
-
generate a warning based on that object rather than throwing it
151
-
(compatible with PHP 5 behaviour)
152
-
</member>
153
-
</simplelist>
152
+
Deprecated as of PHP 8.3.0.
154
153
</entry>
155
154
</row>
156
155
</tbody>
157
156
</tgroup>
158
157
</table>
159
-
</refsect2>
158
+
</para>
160
159
</refsect1>
161
160

162
161
<refsect1 role="parameters">
...
...
@@ -167,32 +166,60 @@
167
166
<term><parameter>assertion</parameter></term>
168
167
<listitem>
169
168
<para>
170
-
The assertion. In PHP 5, this must be either a <type>string</type> to
171
-
be evaluated or a <type>boolean</type> to be tested. In PHP 7, this may
172
-
also be any expression that returns a value, which will be executed and
173
-
the result used to indicate whether the assertion succeeded or failed.
169
+
This is any expression that returns a value, which will be executed
170
+
and the result is used to indicate whether the assertion succeeded or failed.
174
171
</para>
172
+

173
+
<warning>
174
+
<para>
175
+
Prior to PHP 8.0.0, if <parameter>assertion</parameter> was a
176
+
<type>string</type> it was interpreted as PHP code and executed via
177
+
<function>eval</function>.
178
+
This string would be passed to the callback as the third argument.
179
+
This behaviour was <emphasis>DEPRECATED</emphasis> in PHP 7.2.0,
180
+
and <emphasis>REMOVED</emphasis> in PHP 8.0.0.
181
+
</para>
182
+
</warning>
175
183
</listitem>
176
184
</varlistentry>
177
185
<varlistentry>
178
186
<term><parameter>description</parameter></term>
179
187
<listitem>
180
188
<para>
189
+
If <parameter>description</parameter> is an instance of
190
+
<classname>Throwable</classname>, it will be thrown only if the
191
+
<parameter>assertion</parameter> is executed and fails.
192
+
<note>
193
+
<para>
194
+
As of PHP 8.0.0, this is done <emphasis>prior</emphasis> to calling
195
+
the potentially defined assertion callback.
196
+
</para>
197
+
</note>
198
+
<note>
199
+
<para>
200
+
As of PHP 8.0.0, the &object; will be thrown regardless of the configuration of
201
+
<link linkend="ini.assert.exception">assert.exception</link>.
202
+
</para>
203
+
</note>
204
+
<note>
205
+
<para>
206
+
As of PHP 8.0.0, the
207
+
<link linkend="ini.assert.bail">assert.bail</link>
208
+
setting has no effect in this case.
209
+
</para>
210
+
</note>
211
+
</para>
212
+
<para>
213
+
If <parameter>description</parameter> is a &string; this message
214
+
will be used if an exception or a warning is emitted.
181
215
An optional description that will be included in the failure message if
182
216
the <parameter>assertion</parameter> fails.
183
217
</para>
184
-
</listitem>
185
-
</varlistentry>
186
-
<varlistentry>
187
-
<term><parameter>exception</parameter></term>
188
-
<listitem>
189
218
<para>
190
-
In PHP 7, the second parameter can be a
191
-
<classname>Throwable</classname> object instead of a descriptive
192
-
<type>string</type>, in which case this is the object that will be
193
-
thrown if the assertion fails and the
194
-
<link linkend="ini.assert.exception">assert.exception</link>
195
-
configuration directive is enabled.
219
+
If <parameter>description</parameter> is omitted.
220
+
<!-- This does not happen if &null; is passed ... -->
221
+
A default description equal to the source code for the invocation of
222
+
<function>assert</function> is created at compile time.
196
223
</para>
197
224
</listitem>
198
225
</varlistentry>
...
...
@@ -203,7 +230,18 @@
203
230
<refsect1 role="returnvalues">
204
231
&reftitle.returnvalues;
205
232
<para>
206
-
&false; if the assertion is false, &true; otherwise.
233
+
<function>assert</function> will always return &true; if at least one of the following is true:
234
+
</para>
235
+
<simplelist>
236
+
<member><literal>zend.assertions=0</literal></member>
237
+
<member><literal>zend.assertions=-1</literal></member>
238
+
<member><literal>assert.exception=1</literal></member>
239
+
<member><literal>assert.bail=1</literal></member>
240
+
<member>A custom exception object is passed to <parameter>description</parameter>.</member>
241
+
</simplelist>
242
+
<para>
243
+
If none of the conditions are true <function>assert</function> will return &true; if
244
+
<parameter>assertion</parameter> is truthy and &false; otherwise.
207
245
</para>
208
246
</refsect1>
209
247

...
...
@@ -220,23 +258,60 @@
220
258
</thead>
221
259
<tbody>
222
260
<row>
223
-
<entry>7.0.0</entry>
261
+
<entry>8.3.0</entry>
262
+
<entry>
263
+
All <literal>assert.</literal> INI settings have been deprecated.
264
+
</entry>
265
+
</row>
266
+
<row>
267
+
<entry>8.0.0</entry>
268
+
<entry>
269
+
<function>assert</function> will no longer evaluate string arguments, instead they will be
270
+
treated like any other argument. <code>assert($a == $b)</code> should be used instead of
271
+
<code>assert('$a == $b')</code>. The <literal>assert.quiet_eval</literal> &php.ini; directive and
272
+
the <constant>ASSERT_QUIET_EVAL</constant> constant have also been removed, as they would no longer
273
+
have any effect.
274
+
</entry>
275
+
</row>
276
+
<row>
277
+
<entry>8.0.0</entry>
278
+
<entry>
279
+
If <parameter>description</parameter> is an instance of
280
+
<classname>Throwable</classname>, the object is thrown if the assertion
281
+
fails, regardless of the value of
282
+
<link linkend="ini.assert.exception">assert.exception</link>.
283
+
</entry>
284
+
</row>
285
+
<row>
286
+
<entry>8.0.0</entry>
287
+
<entry>
288
+
If <parameter>description</parameter> is an instance of
289
+
<classname>Throwable</classname>, no user callback is called even
290
+
if it set.
291
+
</entry>
292
+
</row>
293
+
<row>
294
+
<entry>8.0.0</entry>
295
+
<entry>
296
+
Declaring a function called <literal>assert()</literal> inside a namespace is
297
+
no longer allowed, and issues <constant>E_COMPILE_ERROR</constant>.
298
+
</entry>
299
+
</row>
300
+
<row>
301
+
<entry>7.3.0</entry>
224
302
<entry>
225
-
<function>assert</function> is now a language construct and not a
226
-
function. <function>assertion</function> can now be an expression.
227
-
The second parameter is now interpreted either as an
228
-
<parameter>exception</parameter> (if a
229
-
<classname>Throwable</classname> object is given), or as the
230
-
<parameter>description</parameter> supported from PHP 5.4.8 onwards.
303
+
Declaring a function called <literal>assert()</literal> inside a namespace
304
+
became deprecated. Such declaration now emits an <constant>E_DEPRECATED</constant>.
231
305
</entry>
232
306
</row>
233
307
<row>
234
-
<entry>5.4.8</entry>
308
+
<entry>7.2.0</entry>
235
309
<entry>
236
-
The <parameter>description</parameter> parameter was added. The
237
-
<parameter>description</parameter> is also now provided to a callback
238
-
function in <constant>ASSERT_CALLBACK</constant> mode as the fourth
239
-
argument.
310
+
Usage of a <type>string</type> as the <parameter>assertion</parameter>
311
+
became deprecated. It now emits an <constant>E_DEPRECATED</constant>
312
+
notice when both <link linkend="ini.assert.active">assert.active</link>
313
+
and <link linkend="ini.zend.assertions">zend.assertions</link> are set
314
+
to <literal>1</literal>.
240
315
</entry>
241
316
</row>
242
317
</tbody>
...
...
@@ -247,174 +322,99 @@
247
322

248
323
<refsect1 role="examples">
249
324
&reftitle.examples;
250
-
<refsect2>
251
-
<title>Traditional assertions (PHP 5 and 7)</title>
252
-
<para>
253
-
<example>
254
-
<title>Handle a failed assertion with a custom handler</title>
255
-
<programlisting role="php">
256
-
<![CDATA[
257
-
<?php
258
-
// Active assert and make it quiet
259
-
assert_options(ASSERT_ACTIVE, 1);
260
-
assert_options(ASSERT_WARNING, 0);
261
-
assert_options(ASSERT_QUIET_EVAL, 1);
262
-

263
-
// Create a handler function
264
-
function my_assert_handler($file, $line, $code)
265
-
{
266
-
echo "<hr>Assertion Failed:
267
-
File '$file'<br />
268
-
Line '$line'<br />
269
-
Code '$code'<br /><hr />";
270
-
}
271
-

272
-
// Set up the callback
273
-
assert_options(ASSERT_CALLBACK, 'my_assert_handler');
274
-

275
-
// Make an assertion that should fail
276
-
assert('mysql_query("")');
277
-
?>
278
-
]]>
279
-
</programlisting>
280
-
</example>
281
-
</para>
282
-
<para>
283
-
<example>
284
-
<title>Using a custom handler to print a description</title>
285
-
<programlisting role="php">
286
-
<![CDATA[
287
-
<?php
288
-
// Active assert and make it quiet
289
-
assert_options(ASSERT_ACTIVE, 1);
290
-
assert_options(ASSERT_WARNING, 0);
291
-
assert_options(ASSERT_QUIET_EVAL, 1);
292
-

293
-
// Create a handler function
294
-
function my_assert_handler($file, $line, $code, $desc = null)
295
-
{
296
-
echo "Assertion failed at $file:$line: $code";
297
-
if ($desc) {
298
-
echo ": $desc";
299
-
}
300
-
echo "\n";
301
-
}
302
-

303
-
// Set up the callback
304
-
assert_options(ASSERT_CALLBACK, 'my_assert_handler');
305
-

306
-
// Make an assertion that should fail
307
-
assert('2 < 1');
308
-
assert('2 < 1', 'Two is less than one');
309
-
?>
310
-
]]>
311
-
</programlisting>
312
-
&example.outputs;
313
-
<screen>
314
-
<![CDATA[
315
-
Assertion failed at test.php:21: 2 < 1
316
-
Assertion failed at test.php:22: 2 < 1: Two is less than one
317
-
]]>
318
-
</screen>
319
-
</example>
320
-
</para>
321
-
</refsect2>
322
-
<refsect2>
323
-
<title>Expectations (PHP 7 only)</title>
324
325
<example>
325
-
<title>Expectations without a custom exception</title>
326
+
<title><function>assert</function> example</title>
326
327
<programlisting role="php">
327
328
<![CDATA[
328
329
<?php
329
-
assert(true == false);
330
+
assert(1 > 2);
330
331
echo 'Hi!';
331
-
?>
332
332
]]>
333
333
</programlisting>
334
334
<para>
335
-
With <link linkend="ini.zend.assertions">zend.assertions</link> set to 0,
335
+
If assertions are enabled (<link linkend="ini.zend.assertions"><literal>zend.assertions=1</literal></link>)
336
336
the above example will output:
337
337
</para>
338
338
<screen>
339
339
<![CDATA[
340
-
Hi!
340
+
Fatal error: Uncaught AssertionError: assert(1 > 2) in example.php:2
341
+
Stack trace:
342
+
#0 example.php(2): assert(false, 'assert(1 > 2)')
343
+
#1 {main}
344
+
thrown in example.php on line 2
341
345
]]>
342
346
</screen>
343
347
<para>
344
-
With <link linkend="ini.zend.assertions">zend.assertions</link> set to 1
345
-
and <link linkend="ini.assert.exception">assert.exception</link> set to 0,
348
+
If assertions are disabled (<literal>zend.assertions=0</literal> or <literal>zend.assertions=-1</literal>)
346
349
the above example will output:
347
350
</para>
348
351
<screen>
349
352
<![CDATA[
350
-
Warning: assert(): assert(true == false) failed in - on line 2
351
353
Hi!
352
354
]]>
353
355
</screen>
356
+
</example>
357
+
<example>
358
+
<title>Using a custom message</title>
359
+
<programlisting role="php">
360
+
<![CDATA[
361
+
<?php
362
+
assert(1 > 2, "Expected one to be greater than two");
363
+
echo 'Hi!';
364
+
]]>
365
+
</programlisting>
354
366
<para>
355
-
With <link linkend="ini.zend.assertions">zend.assertions</link> set to 1
356
-
and <link linkend="ini.assert.exception">assert.exception</link> set to 1,
357
-
the above example will output:
367
+
If assertions are enabled the above example will output:
358
368
</para>
359
369
<screen>
360
370
<![CDATA[
361
-
Fatal error: Uncaught AssertionError: assert(true == false) in -:2
371
+
Fatal error: Uncaught AssertionError: Expected one to be greater than two in example.php:2
362
372
Stack trace:
363
-
#0 -(2): assert(false, 'assert(true == ...')
373
+
#0 example.php(2): assert(false, 'Expected one to...')
364
374
#1 {main}
365
-
thrown in - on line 2
375
+
thrown in example.php on line 2
376
+
]]>
377
+
</screen>
378
+
<para>
379
+
If assertions are disabled the above example will output:
380
+
</para>
381
+
<screen>
382
+
<![CDATA[
383
+
Hi!
366
384
]]>
367
385
</screen>
368
386
</example>
369
387
<example>
370
-
<title>Expectations with a custom exception</title>
388
+
<title>Using a custom exception class</title>
371
389
<programlisting role="php">
372
390
<![CDATA[
373
391
<?php
374
-
class CustomError extends AssertionError {}
392
+
class ArithmeticAssertionError extends AssertionError {}
375
393

376
-
assert(true == false, new CustomError('True is not false!'));
394
+
assert(1 > 2, new ArithmeticAssertionError("Expected one to be greater than two"));
377
395
echo 'Hi!';
378
-
?>
379
396
]]>
380
397
</programlisting>
381
398
<para>
382
-
With <link linkend="ini.zend.assertions">zend.assertions</link> set to 0,
383
-
the above example will output:
384
-
</para>
385
-
<screen>
386
-
<![CDATA[
387
-
Hi!
388
-
]]>
389
-
</screen>
390
-
<para>
391
-
With <link linkend="ini.zend.assertions">zend.assertions</link> set to 1
392
-
and <link linkend="ini.assert.exception">assert.exception</link> set to 0,
393
-
the above example will output:
399
+
If assertions are enabled the above example will output:
394
400
</para>
395
401
<screen>
396
402
<![CDATA[
397
-
Warning: assert(): CustomError: True is not false! in -:4
403
+
Fatal error: Uncaught ArithmeticAssertionError: Expected one to be greater than two in example.php:4
398
404
Stack trace:
399
-
#0 {main} failed in - on line 4
400
-
Hi!
405
+
#0 {main}
406
+
thrown in example.php on line 4
401
407
]]>
402
408
</screen>
403
409
<para>
404
-
With <link linkend="ini.zend.assertions">zend.assertions</link> set to 1
405
-
and <link linkend="ini.assert.exception">assert.exception</link> set to 1,
406
-
the above example will output:
410
+
If assertions are disabled the above example will output:
407
411
</para>
408
412
<screen>
409
413
<![CDATA[
410
-
Fatal error: Uncaught CustomError: True is not false! in -:4
411
-
Stack trace:
412
-
#0 {main}
413
-
thrown in - on line 4
414
+
Hi!
414
415
]]>
415
416
</screen>
416
417
</example>
417
-
</refsect2>
418
418
</refsect1>
419
419

420
420
<refsect1 role="seealso">
...
...
@@ -427,7 +427,6 @@ Stack trace:
427
427
</refsect1>
428
428

429
429
</refentry>
430
-

431
430
<!-- Keep this comment at the end of the file
432
431
Local variables:
433
432
mode: sgml
434
433