Returning PEAR_Error object from constructor
| From: | Mika Tuupola | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Returning PEAR_Error object from constructor | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-314@lists.php.net to get a copy of this message | ||
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.
--
Mika Tuupola http://www.appelsiini.net/~tuupola/