Date: 09/22/00
- Next message: Jeff Stuart: "RE: [phplib-dev] Re: [phplib] How stable is PHPLib-Dev"
- Previous message: Michael Haertl: "[phplib-dev] Return values"
- In reply to: Michael Haertl: "[phplib-dev] Return values"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Michael Haertl wrote:
>
> I've seen, that many phpLib functions return "nothing" on success an
> "false" on error. Is this a bug or a feature?
It's a question of a missing policy on how to write phplib code. There
aren't any naming conventions nor other coding guidelines beside from
"have a look ath the style used in the core...".
> I tried to create an error handler which catches all errors and prints
> my own error message in the end. But by not returning any value on
> success something like this won't work:
>
> $t = new Template;
Try IT[X] ;-). All methods that could fail call $itx->halt() on failure
to save the error message to the array $itx->err and return a value that
indicates an error. If the function would normally return nothing (void)
it will return true or false, if it's expected to return a string it
will return an empty string and if it's excepted to return an array it
will return an empty array on failure.
This is not perfect at all, but its among the best you can.
Have a look at the PEAR discussion on error handling to see how
difficult it's to write a proper error handling in PHP. And have a look
at the new error handling functions of PHP4 that offer callbacks:
set_error_handler() and friends.
> $t->halt_on_error='no';
> $t->set_file('page','file.ihtml') || $this->error[] = 'File not found!'
> ..
>
> How can i determine if the function was successful? As far as i know,
> there's no way to distinguish between undefined and false in PHP.
>
> Am i completely wrong with my proposal to return true on success in
> every phpLib function?
Yes. PHPLib found it's way on error handling. Most phplib classes have a
function halt() that gets called on failure. Override it. If that's not
enough for you, commit an improved version of the class you're worring
about.
Ulf
-- Jede korrekte Antwort kostet. Spendenangebote bitte per PM.--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected> For additional commands, e-mail: phplib-dev-help <email protected>
- Next message: Jeff Stuart: "RE: [phplib-dev] Re: [phplib] How stable is PHPLib-Dev"
- Previous message: Michael Haertl: "[phplib-dev] Return values"
- In reply to: Michael Haertl: "[phplib-dev] Return values"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

