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

From: Date: Tue, 24 Apr 2001 07:41:56 +0000
Subject: Re: Re: cvs: php4 /pear/Crypt CBC.php
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-300@lists.php.net to get a copy of this message
["Tomas V.V.Cox" <cox@idecnet.com>] > Colin Viebrock wrote: > > > > > Since you inherit PEAR, it is better to use $this->raiseError(). That > > > way the user can set default error handling in the Crypt_CBC object. > > > > Thanks ... I just changed it. :) > > > > However, even on an error, the constructor doesn't return a Pear_Error > > object (or Crypt_CBC_Error object). > > In a very cursory review I see in your code: > return $this->raiseError('no initialization vector', null, > PEAR_ERROR_PRINT, null, null, 'Crypt_CBC_Error', false > ); > > If you use PRINT as default error mode, you'll never get a object back. > PEAR_ERROR_RETURN is for that. You will always get an object back as long as execution does not terminate. The reason it's called PEAR_ERROR_RETURN is that this mode _only_ returns the object. 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. 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'); > > 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. :-) > > How can you get the constructor of a class to "construct" a class of some > > other kind? > > In the constructor of your class you need to do a: > $this->PEAR($your_error_class) (or null for PEAR_Errors) call. It will > set the error class of error objs. Then you can raise errors so: > return $this->raiseError ($message, $code, null, null, $debug, null, > null); > > Hope I'm not wrong with the question or the answer :) - Stig -- Stig Sæther Bakken <ssb@fast.no> Fast Search & Transfer ASA, Trondheim, Norway

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