danbeck Thu Mar 8 09:57:13 2001 EDT
Modified files:
/phpdoc/en/functions misc.xml
Log:
added example of die using a function as a parameter
Index: phpdoc/en/functions/misc.xml
diff -u phpdoc/en/functions/misc.xml:1.36 phpdoc/en/functions/misc.xml:1.37
--- phpdoc/en/functions/misc.xml:1.36 Thu Mar 8 08:30:37 2001
+++ phpdoc/en/functions/misc.xml Thu Mar 8 09:57:13 2001
@@ -205,17 +205,46 @@
</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>