added example of die using a function as a parameter

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@42987 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Daniel Beckham 2001-03-08 17:57:13 +00:00
parent 2ca445496c
commit 6cd00fd469

View file

@ -205,17 +205,46 @@ if (defined("CONSTANT")){ // Note that it should be quoted
</funcprototype>
</funcsynopsis>
<simpara>
This language construct outputs a message and terminates parsing
of the script. It does not return anything.
<function>die</function> outputs <parameter>message</parameter>
and terminates parsing of the script. It does not return
anything.
</simpara>
<simpara>
Alternatively, <function>die</function> will also accept a
function as a parameter. That function will be executed
before <function>die</function> terminates parsing of the script.
</simpara>
<para>
<example>
<title>die example</title>
<title><function>die</function> example</title>
<programlisting role="php">
&lt;?php
$filename = '/path/to/data-file';
$file = fopen ($filename, 'r')
or die("unable to open file ($filename)");
?&gt;
</programlisting>
</example>
</para>
<para>
<example>
<title><function>die</function> example using a function</title>
<programlisting role="php">
&lt;?php
function handle_error($msg) {
if ($fp = @fopen("/tmp/error.log", "a")) {
fwrite($fp, $msg, strlen($msg));
fclose($fp);
}
}
if ($bad) {
die(handle_error("Something bad happened.\n"));
}
?&gt;
</programlisting>
</example>