Fw: [PHP-PEAR] easier error reporting
| From: | Ahmad Alhashemi | Date: | Wed, 10 Jan 2001 15:14:11 +0000 |
| Subject: | Fw: [PHP-PEAR] easier error reporting | ||
| Groups: | php.pear | ||
| Request: | Send a blank email to php-pear+get-941@lists.php.net to get a copy of this message | ||
I've sent this by mistake to Stig instead of pear ..
And this is it :
----- Original Message -----
From: "Ahmad Alhashemi" <mailings@arabbuilder.com>
To: "Stig S. Bakken" <ssb@fast.no>
Sent: Monday, January 08, 2001 9:06 AM
Subject: Re: [PHP-PEAR] easier error reporting
> > Hi,
> >
> > The PEAR_Error class is nice and all, but it's not easy enough to use
> > and I feel it is currently configurable in the wrong way (too much
> > control deep down, too little control on top). DB lets you set the
> > default behaviour for errors with origin within that object with the
> > setErrorHandler() and raiseError() methods, maybe this functionality
> > belongs in the base PEAR class? Example:
> >
> > $myObj->setErrorHandling(PEAR_ERROR_CALLBACK, array($errObj,
> > "myErrorHandler"));
> >
> > ...then later in $myObj's code (instead of "return new
> > PEAR_Error(...)"):
> >
> > $this->raiseError("blah");
> >
> > There should be a global default error handler too, so you don't have to
> > configure it for every object. That'd have to be done with a function
> > or static method:
> >
> > PEAR::setDefaultErrorHandling(PEAR_ERROR_PRINT);
> >
> > IMHO, something like this is necessary to make the PEAR error system
> > more than just a good idea.
> > My only concern is bloating the PEAR class. Any opinions?
> >
> > - Stig
>
> For myself ( my own projects ) i created something called operations, with
a
> class called OperationManagment,
> ALL my API functions return an object of this class, this class will
contain
> :
> 1) a code indicating what happend.
> 2) any error messages encountered.
> 3) the results of the operation.
> 4) the final statement ( optional ) like : "The queary was sent to the
> database." or anything.
>
> in each Pear function an object of this class id created and filled with
the
> data as you go down
> with the code, if you encounter more than one error in the data you can
> report them all and return
> just before executing the real operation ( eg: the query ), if no data
> errors occur then you can execute
> ( the query ), if the query encountered any problem you report a (
technical
> error ) and return, if
> everything goes ok you report a success and return with the results hash
in
> the operation object filled
> the the resutls, examples of how to use it :
>
> class My_Class() {
> function myFunction($name,$email) {
> $operation = new OperationManagemnt;
> if (not_valid_email)
> $operation->dataError( "The e-mail you entered was
invalid." );
> if (too_long_name)
> $operation->dataError( "The must musn't be more that xxx
> character long." );
>
> if ($operation->status() != OPERATION_WORKING) {
> return $operation; // something went wrong.
> }
>
> $result = mail( $email, "Hi ".$name, "Just want to say hi" );
> if (!$result) {
> $operation->techError( "Couldn't send the email" );
> return $operation;
> }
> $operation->done( "Email was sent successfully." );
> }
>
> The functions dataError, criticalError, and techError will change the
status
> code of the object
> to OPERATION_DATA_ERROR, OPERATION_CRITICAL_ERROR, and
> OPERATION_TECH_ERORR respectivly ..
>
> * the critical error is a data error that can't be solved by the user (
> trying to delete a non-existing record )
>
> The status defaults to OPERATION_WORKING that there were no outcomes yet (
> no errors
> reported, no success reported ).
> If the operation was done successfully the status will be OPERATION_DONE
>
> i couldn't show all the API in this example, it was just to demonstrate
the
> idea ..
> other methods might be :
>
> $operation->SetResult($key, $value);
> This is used by the function that will return the object to set any of the
> results like
> if the function is supposed to return a row of data this will happen :
> $operation->SetResult("row", $row);
>
> $operation->GetResult($key);
> This will return the value from results of the operation, so if in your
> program you do :
> $results = My_Class->fetch_row( $result );
> $row = $results( "row" );
>
> so GetResult and SetResults are accessors to a hash containing all the
> results of the operation.
>
> This class will achieve :
> 1) more than one error can be reported, no need to report an error at a
> time.
> 2) more that one result can be returned.
> 3) everything is now easier to access and use.
> 4) one type of data is always returned by all the functions.
>
> of course this can be considered as a start and modified in a lot of ways.
>