Re: Suggestion for fetchInto
| From: | (Stig Sæther Bakken) | Date: | Sat, 21 Apr 2001 22:34:19 +0000 |
| Subject: | Re: Suggestion for fetchInto | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-286@lists.php.net to get a copy of this message | ||
["Tomas V.V.Cox" <cox@idecnet.com>]
> "Tomas V.V.Cox" wrote:
> >
> > Hi,
>
> Hi Tomas,
>
> > What do you think about setting the DB_OK constant to true o 1? It could
> > improve usability for some functions for ex: fetchInto().
> >
> > Now you need to do:
> >
> > while (DB_OK === $res->fetchInto($row)) {
> > ...
> > }
> >
> > With the new value, people could simply use:
> >
> > while ($res->fetchInto($row)) {
> > ...
> > }
> >
>
> The approach to improve the fetch row user usability could be this:
>
> - DB_extensions always returns DB_errors on errors as they actually do,
> so if you set up a default PEAR error hlandler, errors could be catched
> by it.
Whether a function that raises an error returns the error object or
not should never vary, that only leads to confusion, obscure bugs and
grinding of teeth. Besides, if you set the default error handler to
for example PEAR_ERROR_PRINT, you will still want the object back.
> - Change DB_result::fetchInto to only returns "null" or "array". If it
> get an error from the extention, can use trigger_error (as used in
> PEAR::setErrorHandling) to notice it but always returns "null" in this
> case.
> - The DB_OK constant value should be changed from "0" to "1", so don't
> disturbs loops like while.
Tomas, this patch breaks consistency in a way that will confuse users.
If we want to get people used to the idea of returned error objects,
introducing little exceptions here and there will only be disruptive.
What you're doing in the patch below is basically replacing the PEAR
error mechanism with trigger_error() in _one_ case inside one of
PEAR's classes. If we want to offer an error system, we should stick
to it.
Also, keep in mind how many variations you can have on the behaviour
of trigger_error(): track_errors option, error_reporting option,
error_log option, custom error handlers set by the script that are
also outside PEAR's error concept.
I agree that the current syntax of fetchInto is a little bit verbose,
but I don't think this is the way to deal with it. We're talking
about (strlen("DB_OK === ") = 10) characters more typing here.
- Stig
--
Stig Sæther Bakken <ssb@fast.no>
Fast Search & Transfer ASA, Trondheim, Norway