Re: Returning PEAR_Error object from constructor

From: Date: Wed, 25 Apr 2001 13:56:36 +0000
Subject: Re: Returning PEAR_Error object from constructor
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-315@lists.php.net to get a copy of this message
[Mika Tuupola <tuupola@appelsiini.net>] > On 24 Apr 2001, Stig Sæther Bakken wrote: > > > > But when, I run it: > > > > > > $c = new Crypt_CBC('', 'des'); > > > > > > $c is not a PEAR_Error object. That's what I'm trying to do. :) > > > Sorry, the constructor's return value is ignored, the "new" operator > > will always give you the instantiated object back. What you need to > > do is to take everything that can fail out of the constructor and add > > an initialization method. > > > > > Overwriting the $this variable is not a good idea. :-) > > > > > > Agreed. :) However, this seems to be the only way to get the Crypt_CBC > > > constructor to not create a Crypt_CBC object. > > > > Huh, does that work? > > Yes it seems to work. This brings me a question, is that a bug > or a feature. Meaning, would it be considered bad coding (in > PEAR's point of view) if you returned the error object from > constructor? > > In some cases I find it more elegan't to give all the needed > parameters to constructor rather than allways have a separate > initialization method. The question is whether this is an "officially supported" Zend feature. Zeev, is overwriting $this in the constructor to have "new" return a different object a bug/misfeature or can we rely on it? :-) - Stig -- Stig Sæther Bakken <ssb@fast.no> Fast Search & Transfer ASA, Trondheim, Norway

« previous php.pear.dev (#315) next »