mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 17:08:54 +00:00
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:
parent
2ca445496c
commit
6cd00fd469
1 changed files with 32 additions and 3 deletions
|
@ -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">
|
||||
<?php
|
||||
|
||||
$filename = '/path/to/data-file';
|
||||
$file = fopen ($filename, 'r')
|
||||
or die("unable to open file ($filename)");
|
||||
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title><function>die</function> example using a function</title>
|
||||
<programlisting role="php">
|
||||
<?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"));
|
||||
}
|
||||
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
|
Loading…
Reference in a new issue