Re: Re: cvs: php4 /pear/Crypt CBC.php

From: Date: Tue, 24 Apr 2001 21:34:14 +0000
Subject: Re: Re: cvs: php4 /pear/Crypt CBC.php
References: 1 2 3 4 5 6  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-309@lists.php.net to get a copy of this message
["Colin Viebrock" <colin@easyDNS.com>] > > Colin, in general it's not a good idea to pass mode in raiseError, > > because it takes control away from the user. If I have a callback > > function that I want to use for all error handling, it will never be > > called when you override my default mode in the raiseError call. > > Fair enough. :) > > > If you call the PEAR constructor with 'Crypt_CBC_Error' as the first > > parameter (or no parameter, you don't really need to override > > PEAR_Error unless you really want a different prefix), you only need > > to specify the error message in your raiseError call: > > > > function Crypt_CBC(...) > > { > > $this->PEAR(); > > } > > ... > > return $this->raiseError('no initialization vector'); > > Okay I changed my code to something like this: > > function Crypt_CBC($key, $cipher) > { > $this->PEAR(); > if (!$key) { > return $this->raiseError('no key'); > } > ... > } > > 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. > > > > I don't need to do something like this, do I? > > > > > > > > if (something bad) { > > > > $this = PEAR::raiseError(...) > > > > return $this; > > > > } > > > > 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? > Sorry if I'm being difficult. :) Ditto. ;-) - Stig -- Stig Sæther Bakken <ssb@fast.no> Fast Search & Transfer ASA, Trondheim, Norway

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