Added note about backward compatibility of extending exceptions for PHP < 5.3.0

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@301446 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Richard Quadling 2010-07-21 16:02:05 +00:00
parent 55ac051503
commit fdba617bc8

View file

@ -173,7 +173,7 @@ class Exception
</para>
</note>
<example>
<title>Extending the Exception class</title>
<title>Extending the Exception class (PHP V5.3.+)</title>
<programlisting role="php">
<![CDATA[
<?php
@ -289,6 +289,39 @@ echo "\n\n";
?>
]]>
</programlisting>
<note>
Versions of PHP 5, prior to PHP 5.3.0 do not support nesting of exceptions.
The following code fragment can be used as a replacement MyException class
if you wish to run this example.
<programlisting role="php">
<![CDATA[
<?php
/**
* Define a custom exception class
*/
class MyException extends Exception
{
// Redefine the exception so message isn't optional
public function __construct($message, $code = 0) {
// some code
// make sure everything is assigned properly
parent::__construct($message, $code);
}
// custom string representation of object
public function __toString() {
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}
public function customFunction() {
echo "A custom function for this type of exception\n";
}
}
?>
]]>
</programlisting>
</note>
</example>
</sect1>