There are two other problems with this approach:

One is that by creating the exception in the getException() method, this makes 
stack traces nonstandard and difficult to interpret.  The stack trace shows 
every exception has being created in the getException() method instead of where 
getException() is called from.  

It's not a good design if developers are required to know that they need to 
ignore the top item in the stack trace, but look one level deeper.  But only 
for Zend exceptions.  Unless a developer decides to use getException() for 
their own application-specific exceptions.  The point is that this usage is 
confusing and nonstandard.

Another problem with the getException() method below is that it assumes that 
all classes have exactly one exception, named after the class with '_Exception' 
appended.  This doesn't work for example for Zend_Gdata_AuthException.  

We should be defining exceptions by their root cause, not for the class that 
throws them.  Some have suggested that we should be using the standard SPL 
exceptions (InvalidArgumentException, etc.).

Regards,
Bill Karwin

> -----Original Message-----
> From: Matthew Weier O'Phinney [mailto:[EMAIL PROTECTED]
> Sent: Thursday, April 05, 2007 6:10 AM
> To: [email protected]
> Subject: Re: [fw-general] The small offer use Zend_Exception
> 
> We did this once already -- search on nabble for 'Zend::exception()' for
> the various discussions (I'm unable to pull up nabble right now;
> otherwise, I'd provide links).
> 
> Basically, it was a premature optimization at best, particularly with
> the opcode enhancements made in the 5.2 branch of PHP. Additionally, it
> makes type hinting difficult when the exception classes are not already
> loaded.
> 
> -- Roman1975 <[EMAIL PROTECTED]> wrote
> (on Thursday, 05 April 2007, 04:51 AM -0700):
> >
> > <?php
> > require_once('Zend/Exception.php');
> >
> > /**
> >  * My offer on classes of exceptions
> > * To not create it is a lot of files which describe
> > * Set именна to classes of exceptions:
> > *
> > *
> > */
> >
> >
> > class ARM
> > {
> >
> >     /**
> >      * The automatic generator of exceptions if $name a line that will
> be
> > exception is generated
> >      * With given a name if object that will be exception and a name of
> > given object is generated,
> >      * In anyone cases will are added to a name prefix _Exception
> >      *
> >      *
> >      * @param string|object $name
> >      * @param string $message
> >      * @param int $code
> >      */
> >     public static function getException($name, $message='', $code=0)
> >     {
> >         if (is_string($name)) {
> >             $nameClass = $name.'_Exception';
> >         } elseif (is_object($name)) {
> >             $nameClass = get_class($name).'_Exception';
> >         } else {
> >             throw new Zend_Exception(_("You should transfer in the first
> > parameter or a name or
> >             Object of a class on the basis of which the exclusive
> situation
> > will be generated"));
> >         }
> >
> >         if (false === class_exists($nameClass)) {
> >
> >             $cod = '
> > class '.$nameClass.' extends Zend_Exception
> > {
> >
> > }
> >
> > ';
> >             eval($cod);
> >         }
> >         $obj = new $nameClass($message, $code);
> >         /[EMAIL PROTECTED] $obj Exception*/
> >         throw $obj;
> >     }
> > }
> > class testRRR
> > {
> >     public function __construct()
> >     {
> >         ARM::getException($this, 'ok', 1);
> >         // or
> >         //ARM::getException('Others', 'ok', 1);
> >     }
> > }
> >
> > new testRRR();
> > --
> > View this message in context: http://www.nabble.com/The-small-offer-use-
> Zend_Exception-tf3531128s16154.html#a9854358
> > Sent from the Zend Framework mailing list archive at Nabble.com.
> >
> 
> --
> Matthew Weier O'Phinney
> PHP Developer            | [EMAIL PROTECTED]
> Zend - The PHP Company   | http://www.zend.com/

Reply via email to