Mentioning that shutdown functions and object destructors will be called even if exit() is called.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@293992 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Daniel Egeberg 2010-01-25 15:28:23 +00:00
parent dcab108b3c
commit 33f7afff50
3 changed files with 46 additions and 1 deletions

View file

@ -97,6 +97,11 @@ $obj = new MyDestructableClass();
explicitly call <function>parent::__destruct</function> in the destructor
body.
</para>
<para>
The destructor will be called even if script execution is stopped using
<function>exit</function>. Calling <function>exit</function> in a destructor
will prevent the remaining shutdown routines from executing.
</para>
<note>
<para>
Destructors called during the script shutdown have HTTP headers already

View file

@ -16,7 +16,8 @@
</methodsynopsis>
<para>
Registers the function named by <parameter>function</parameter> to be
executed when script processing is complete.
executed when script processing is complete or when <function>exit</function>
is called.
</para>
<para>
Multiple calls to <function>register_shutdown_function</function> can be

View file

@ -18,6 +18,9 @@
</methodsynopsis>
<para>
Terminates execution of the script.
<link linkend="function.register-shutdown-function">Shutdown functions</link>
and <link linkend="language.oop5.decon.destructor">object destructors</link>
will always be executed even if <function>exit</function> is called.
</para>
</refsect1>
@ -97,6 +100,42 @@ exit(0376); //octal
</programlisting>
</example>
</para>
<para>
<example>
<title>Shutdown functions and destructors run regardless</title>
<programlisting role="php">
<![CDATA[
<?php
class Foo
{
public function __destruct()
{
echo 'Destruct: ' . __METHOD__ . '()' . PHP_EOL;
}
}
function shutdown()
{
echo 'Shutdown: ' . __FUNCTION__ . '()' . PHP_EOL;
}
$foo = new Foo();
register_shutdown_function('shutdown');
exit();
echo 'This will not be output.';
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Shutdown: shutdown()
Destruct: Foo::__destruct()
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">