mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
55ac051503
commit
fdba617bc8
1 changed files with 34 additions and 1 deletions
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue