PageRenderTime 54ms CodeModel.GetById 19ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/.vim/manuals/php/function.set-error-handler.html

https://bitbucket.org/fally/configs
HTML | 369 lines | 308 code | 61 blank | 0 comment | 0 complexity | 0c97cc02410369786404a782b1598c21 MD5 | raw file
  1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2<html>
  3 <head>
  4  <title>Sets a user-defined error handler function</title>
  5  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6 </head>
  7 <body><div style="text-align: center;">
  8 <div class="prev" style="text-align: left; float: left;"><a href="function.restore-exception-handler.html">restore_exception_handler</a></div>
  9 <div class="next" style="text-align: right; float: right;"><a href="function.set-exception-handler.html">set_exception_handler</a></div>
 10 <div class="up"><a href="ref.errorfunc.html">Error Handling Functions</a></div>
 11 <div class="home"><a href="index.html">PHP Manual</a></div>
 12</div><hr /><div id="function.set-error-handler" class="refentry">
 13 <div class="refnamediv">
 14  <h1 class="refname">set_error_handler</h1>
 15  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5)</p><p class="refpurpose"><span class="refname">set_error_handler</span> &mdash; <span class="dc-title">Sets a user-defined error handler function</span></p>
 16
 17 </div>
 18
 19 <div class="refsect1 description">
 20  <h3 class="title">Description</h3>
 21  <div class="methodsynopsis dc-description">
 22   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>set_error_handler</b></b></span>
 23    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.callback" class="type callback">callback</a></span> <tt class="parameter">$error_handler</tt></span>
 24   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$error_types</tt></span>
 25  ] )</div>
 26
 27  <p class="para rdfs-comment">
 28   Sets a user function (<i><tt class="parameter">error_handler</tt></i>
 29) to handle
 30   errors in a script.
 31  </p>
 32  <p class="para">
 33   This function can be used for defining your own way of handling errors
 34   during runtime, for example in applications in which you need to do
 35   cleanup of data/files when a critical error happens, or when you need
 36   to trigger an error under certain conditions (using
 37   <a href="function.trigger-error.html" class="function">trigger_error()</a>).
 38  </p>
 39  <p class="para">
 40   It is important to remember that the standard PHP error handler is completely
 41   bypassed. <a href="function.error-reporting.html" class="function">error_reporting()</a> settings will have no effect
 42   and your error handler will be called regardless - however you are still
 43   able to read the current value of <a href="errorfunc.configuration.html#ini.error-reporting" class="link">error_reporting</a> and
 44   act appropriately. Of particular note is that this value will be 0 if the
 45   statement that caused the error was prepended by the
 46   <a href="language.operators.errorcontrol.html" class="link">@ error-control
 47   operator</a>.
 48  </p>
 49  <p class="para">
 50   Also note that it is your responsibility to <a href="function.die.html" class="function">die()</a> if
 51   necessary. If the error-handler function returns, script execution
 52   will continue with the next statement after the one that caused an error.
 53  </p>
 54  <p class="para">
 55   The following error types cannot be handled with a user defined
 56   function: <b><tt>E_ERROR</tt></b>, <b><tt>E_PARSE</tt></b>,
 57   <b><tt>E_CORE_ERROR</tt></b>, <b><tt>E_CORE_WARNING</tt></b>,
 58   <b><tt>E_COMPILE_ERROR</tt></b>,
 59   <b><tt>E_COMPILE_WARNING</tt></b>, and
 60   most of <b><tt>E_STRICT</tt></b> raised in the file where
 61   <b>set_error_handler()</b> is called.
 62  </p>
 63  <p class="para">
 64   If errors occur before the script is executed (e.g. on file uploads) the 
 65   custom error handler cannot be called since it is not registered at that 
 66   time.
 67  </p>
 68 </div>
 69
 70
 71 <div class="refsect1 parameters">
 72  <h3 class="title">Parameters</h3>
 73  <p class="para">
 74   <dl>
 75
 76    <dt>
 77
 78     <span class="term"><i><tt class="parameter">error_handler</tt></i>
 79</span>
 80
 81     <dd>
 82
 83      <p class="para">
 84       The user function needs to accept two parameters: the error code, and a
 85       string describing the error. Then there are three optional parameters 
 86       that may be supplied: the filename in which the error occurred, the
 87       line number in which the error occurred, and the context in which the
 88       error occurred (an array that points to the active symbol table at the
 89       point the error occurred).  The function can be shown as:
 90      </p>
 91      <p class="para">
 92       <div class="methodsynopsis dc-description">
 93         <span class="methodname"><b><span class="replaceable">handler</span></b></span>
 94         ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$errno</tt></span>
 95        , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$errstr</tt></span>
 96        [, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$errfile</tt></span>
 97        [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$errline</tt></span>
 98        [, <span class="methodparam"><span class="type">array</span> <tt class="parameter">$errcontext</tt></span>
 99       ]]] )</div>
100
101       <dl>
102
103        <dt>
104
105         <span class="term"><i><tt class="parameter">errno</tt></i>
106</span>
107
108         <dd>
109
110          <span class="simpara">
111           The first parameter, <i><tt class="parameter">errno</tt></i>
112, contains the
113           level of the error raised, as an integer.
114          </span>
115         </dd>
116
117        </dt>
118
119        <dt>
120
121         <span class="term"><i><tt class="parameter">errstr</tt></i>
122</span>
123
124         <dd>
125
126          <span class="simpara">
127           The second parameter, <i><tt class="parameter">errstr</tt></i>
128, contains the
129           error message, as a string.
130          </span>
131         </dd>
132
133        </dt>
134
135        <dt>
136
137         <span class="term"><i><tt class="parameter">errfile</tt></i>
138</span>
139
140         <dd>
141
142          <span class="simpara">
143           The third parameter is optional, <i><tt class="parameter">errfile</tt></i>
144,
145           which contains the filename that the error was raised in, as a string.
146          </span>
147         </dd>
148
149        </dt>
150
151        <dt>
152
153         <span class="term"><i><tt class="parameter">errline</tt></i>
154</span>
155
156         <dd>
157
158          <span class="simpara">
159           The fourth parameter is optional, <i><tt class="parameter">errline</tt></i>
160,
161           which contains the line number the error was raised at, as an integer.
162          </span>
163         </dd>
164
165        </dt>
166
167        <dt>
168
169         <span class="term"><i><tt class="parameter">errcontext</tt></i>
170</span>
171
172         <dd>
173
174          <span class="simpara">
175           The fifth parameter is optional, <i><tt class="parameter">errcontext</tt></i>
176,
177           which is an array that points to the active symbol table at the point
178           the error occurred.  In other words, <i><tt class="parameter">errcontext</tt></i>
179
180           will contain an array of every variable that existed in the scope the
181           error was triggered in.
182           User error handler must not modify error context.
183          </span>
184         </dd>
185
186        </dt>
187
188       </dl>
189
190      </p>
191      <p class="para">
192       If the function returns <b><tt>FALSE</tt></b> then the normal error handler continues.
193      </p>
194     </dd>
195
196    </dt>
197
198    <dt>
199
200     <span class="term"><i><tt class="parameter">error_types</tt></i>
201</span>
202
203     <dd>
204
205      <p class="para">
206       Can be used to mask the triggering of the
207       <i><tt class="parameter">error_handler</tt></i>
208 function just like the <a href="errorfunc.configuration.html#ini.error-reporting" class="link">error_reporting</a> ini setting 
209       controls which errors are shown. Without this mask set the
210       <i><tt class="parameter">error_handler</tt></i>
211 will be called for every error
212       regardless to the setting of the <a href="errorfunc.configuration.html#ini.error-reporting" class="link">error_reporting</a> setting.
213      </p>
214     </dd>
215
216    </dt>
217
218   </dl>
219
220  </p>
221 </div>
222
223
224 <div class="refsect1 returnvalues">
225  <h3 class="title">Return Values</h3>
226  <p class="para">
227   Returns a string containing the previously defined
228   error handler (if any), or <b><tt>NULL</tt></b> on error. If the previous handler
229   was a class method, this function will return an indexed array with
230   the class and the method name.
231  </p>
232 </div>
233
234
235 <div class="refsect1 changelog">
236  <h3 class="title">ChangeLog</h3>
237  <p class="para">
238   <table class="informaltable">
239    <colgroup>
240
241     <thead valign="middle">
242      <tr valign="middle">
243       <th colspan="1">Version</th>
244       <th colspan="1">Description</th>
245      </tr>
246
247     </thead>
248
249     <tbody valign="middle" class="tbody">
250      <tr valign="middle">
251       <td colspan="1" rowspan="1" align="left">5.2.0</td>
252       <td colspan="1" rowspan="1" align="left">
253        The error handler must return <b><tt>FALSE</tt></b> to populate <a href="reserved.variables.phperrormsg.html" class="link">$php_errormsg</a>.
254       </td>
255      </tr>
256
257      <tr valign="middle">
258       <td colspan="1" rowspan="1" align="left">5.0.0</td>
259       <td colspan="1" rowspan="1" align="left">
260        The <i><tt class="parameter">error_types</tt></i>
261 parameter was introduced.
262       </td>
263      </tr>
264
265      <tr valign="middle">
266       <td colspan="1" rowspan="1" align="left">4.3.0</td>
267       <td colspan="1" rowspan="1" align="left">
268        Instead of a function name, an array containing an object reference 
269        and a method name can also be supplied as the
270        <i><tt class="parameter">error_handler</tt></i>
271.
272       </td>
273      </tr>
274
275      <tr valign="middle">
276       <td colspan="1" rowspan="1" align="left">4.0.2</td>
277       <td colspan="1" rowspan="1" align="left">
278        Three optional parameters for the <i><tt class="parameter">error_handler</tt></i>
279
280        user function was introduced. These are the filename, the line number, 
281        and the context.
282       </td>
283      </tr>
284
285     </tbody>
286    </colgroup>
287
288   </table>
289  </p>
290 </div>
291
292
293 <div class="refsect1 examples">
294  <h3 class="title">Examples</h3>
295  <p class="para">
296   <div class="example">
297    <p><b>Example #1 Error handling with <b>set_error_handler()</b> and <a href="function.trigger-error.html" class="function">trigger_error()</a></b></p>
298    <div class="example-contents"><p>
299     The example below shows the handling of internal exceptions by
300     triggering errors and handling them with a user defined function:
301    </p></div>
302    <div class="example-contents">
303<div class="phpcode"><code><span style="color: #000000">
304<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;error&nbsp;handler&nbsp;function<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">myErrorHandler</span><span style="color: #007700">(</span><span style="color: #0000BB">$errno</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$errstr</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$errfile</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$errline</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(</span><span style="color: #0000BB">$errno</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;b&gt;My&nbsp;ERROR&lt;/b&gt;&nbsp;[$errno]&nbsp;$errstr&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&nbsp;&nbsp;Fatal&nbsp;error&nbsp;on&nbsp;line&nbsp;$errline&nbsp;in&nbsp;file&nbsp;$errfile"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">",&nbsp;PHP&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">PHP_VERSION&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"&nbsp;("&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">PHP_OS&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">")&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Aborting...&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">E_USER_WARNING</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;b&gt;My&nbsp;WARNING&lt;/b&gt;&nbsp;[$errno]&nbsp;$errstr&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">E_USER_NOTICE</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;b&gt;My&nbsp;NOTICE&lt;/b&gt;&nbsp;[$errno]&nbsp;$errstr&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;default:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Unknown&nbsp;error&nbsp;type:&nbsp;[$errno]&nbsp;$errstr&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Don't&nbsp;execute&nbsp;PHP&nbsp;internal&nbsp;error&nbsp;handler&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">return&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;function&nbsp;to&nbsp;test&nbsp;the&nbsp;error&nbsp;handling<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">scale_by_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$vect</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$scale</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">is_numeric</span><span style="color: #007700">(</span><span style="color: #0000BB">$scale</span><span style="color: #007700">)&nbsp;||&nbsp;</span><span style="color: #0000BB">$scale&nbsp;</span><span style="color: #007700">&lt;=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"log(x)&nbsp;for&nbsp;x&nbsp;&lt;=&nbsp;0&nbsp;is&nbsp;undefined,&nbsp;you&nbsp;used:&nbsp;scale&nbsp;=&nbsp;$scale"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$vect</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"Incorrect&nbsp;input&nbsp;vector,&nbsp;array&nbsp;of&nbsp;values&nbsp;expected"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">E_USER_WARNING</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$temp&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach(</span><span style="color: #0000BB">$vect&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$pos&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">is_numeric</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"Value&nbsp;at&nbsp;position&nbsp;$pos&nbsp;is&nbsp;not&nbsp;a&nbsp;number,&nbsp;using&nbsp;0&nbsp;(zero)"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">E_USER_NOTICE</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$temp</span><span style="color: #007700">[</span><span style="color: #0000BB">$pos</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">log</span><span style="color: #007700">(</span><span style="color: #0000BB">$scale</span><span style="color: #007700">)&nbsp;*&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$temp</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;to&nbsp;the&nbsp;user&nbsp;defined&nbsp;error&nbsp;handler<br /></span><span style="color: #0000BB">$old_error_handler&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">set_error_handler</span><span style="color: #007700">(</span><span style="color: #DD0000">"myErrorHandler"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;trigger&nbsp;some&nbsp;errors,&nbsp;first&nbsp;define&nbsp;a&nbsp;mixed&nbsp;array&nbsp;with&nbsp;a&nbsp;non-numeric&nbsp;item<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"vector&nbsp;a\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5.5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">43.3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">21.11</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;now&nbsp;generate&nbsp;second&nbsp;array<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"----\nvector&nbsp;b&nbsp;-&nbsp;a&nbsp;notice&nbsp;(b&nbsp;=&nbsp;log(PI)&nbsp;*&nbsp;a)\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">/*&nbsp;Value&nbsp;at&nbsp;position&nbsp;$pos&nbsp;is&nbsp;not&nbsp;a&nbsp;number,&nbsp;using&nbsp;0&nbsp;(zero)&nbsp;*/<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">scale_by_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">M_PI</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;this&nbsp;is&nbsp;trouble,&nbsp;we&nbsp;pass&nbsp;a&nbsp;string&nbsp;instead&nbsp;of&nbsp;an&nbsp;array<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"----\nvector&nbsp;c&nbsp;-&nbsp;a&nbsp;warning\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">/*&nbsp;Incorrect&nbsp;input&nbsp;vector,&nbsp;array&nbsp;of&nbsp;values&nbsp;expected&nbsp;*/<br /></span><span style="color: #0000BB">$c&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">scale_by_log</span><span style="color: #007700">(</span><span style="color: #DD0000">"not&nbsp;array"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2.3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;NULL<br /><br />//&nbsp;this&nbsp;is&nbsp;a&nbsp;critical&nbsp;error,&nbsp;log&nbsp;of&nbsp;zero&nbsp;or&nbsp;negative&nbsp;number&nbsp;is&nbsp;undefined<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"----\nvector&nbsp;d&nbsp;-&nbsp;fatal&nbsp;error\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">/*&nbsp;log(x)&nbsp;for&nbsp;x&nbsp;&lt;=&nbsp;0&nbsp;is&nbsp;undefined,&nbsp;you&nbsp;used:&nbsp;scale&nbsp;=&nbsp;$scale"&nbsp;*/<br /></span><span style="color: #0000BB">$d&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">scale_by_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">2.5</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$d</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;Never&nbsp;reached<br /></span><span style="color: #0000BB">?&gt;</span>
305</span>
306</code></div>
307    </div>
308
309    <div class="example-contents"><p>The above example will output 
310something similar to:</p></div>
311    <div class="example-contents"><pre>
312<div class="cdata"><pre>
313vector a
314Array
315(
316    [0] =&gt; 2
317    [1] =&gt; 3
318    [2] =&gt; foo
319    [3] =&gt; 5.5
320    [4] =&gt; 43.3
321    [5] =&gt; 21.11
322)
323----
324vector b - a notice (b = log(PI) * a)
325&lt;b&gt;My NOTICE&lt;/b&gt; [1024] Value at position 2 is not a number, using 0 (zero)&lt;br /&gt;
326Array
327(
328    [0] =&gt; 2.2894597716988
329    [1] =&gt; 3.4341896575482
330    [2] =&gt; 0
331    [3] =&gt; 6.2960143721717
332    [4] =&gt; 49.566804057279
333    [5] =&gt; 24.165247890281
334)
335----
336vector c - a warning
337&lt;b&gt;My WARNING&lt;/b&gt; [512] Incorrect input vector, array of values expected&lt;br /&gt;
338NULL
339----
340vector d - fatal error
341&lt;b&gt;My ERROR&lt;/b&gt; [256] log(x) for x &lt;= 0 is undefined, you used: scale = -2.5&lt;br /&gt;
342  Fatal error on line 35 in file trigger_error.php, PHP 5.2.1 (FreeBSD)&lt;br /&gt;
343Aborting...&lt;br /&gt;
344</pre></div>
345    </pre></div>
346   </div>
347  </p>
348 </div>
349
350
351 <div class="refsect1 seealso">
352  <h3 class="title">See Also</h3>
353  <p class="para">
354   <ul class="simplelist">
355    <li class="member"><a href="function.error-reporting.html" class="function" rel="rdfs-seeAlso">error_reporting()</a></li>
356    <li class="member"><a href="function.restore-error-handler.html" class="function" rel="rdfs-seeAlso">restore_error_handler()</a></li>
357    <li class="member"><a href="function.trigger-error.html" class="function" rel="rdfs-seeAlso">trigger_error()</a></li>
358    <li class="member"><a href="errorfunc.constants.html" class="link">error level constants</a></li>
359    <li class="member">information about the <a href="language.pseudo-types.html#language.types.callback" class="link">callback</a> type</li>
360   </ul>
361  </p>
362 </div>
363
364</div><hr /><div style="text-align: center;">
365 <div class="prev" style="text-align: left; float: left;"><a href="function.restore-exception-handler.html">restore_exception_handler</a></div>
366 <div class="next" style="text-align: right; float: right;"><a href="function.set-exception-handler.html">set_exception_handler</a></div>
367 <div class="up"><a href="ref.errorfunc.html">Error Handling Functions</a></div>
368 <div class="home"><a href="index.html">PHP Manual</a></div>
369</div></body></html>