svn: /phpdoc/en/trunk/language/ exceptions.xml

From: Date: Wed, 21 Jul 2010 16:02:05 +0000
Subject: svn: /phpdoc/en/trunk/language/ exceptions.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-6907@lists.php.net to get a copy of this message
rquadling Wed, 21 Jul 2010 16:02:05 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=301446 Log: Added note about backward compatibility of extending exceptions for PHP < 5.3.0 Changed paths: U phpdoc/en/trunk/language/exceptions.xml Modified: phpdoc/en/trunk/language/exceptions.xml =================================================================== --- phpdoc/en/trunk/language/exceptions.xml 2010-07-21 14:44:20 UTC (rev 301445) +++ phpdoc/en/trunk/language/exceptions.xml 2010-07-21 16:02:05 UTC (rev 301446) @@ -173,7 +173,7 @@ </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 @@ ?> ]]> </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>

« previous php.doc.cvs (#6907) next »