I have a function which should convey two things upon its completion.
First, the return value of the function, consisting of some text. Second,
it should convey an "error status", which, could be either a simple
"success", or a number of levels of failure.
(For the record, it's a logon script indicating success/failure, but I'll
probably use this elsewhere.)
The way I see it, I have a couple options, maybe more:
1.) Return an array. The first element is the return value, the second is
the status code.
- Advantages: No global variables used. No "status check" functions.
- Disadvantages: Can't use a simple "if (function())" call to determine
success/failure, since it will always return "true". Need to deal with a
structure (array) instead of a simple variable.
2.) Return the string on success, or false on failure. Set a global
variable to the exit status, and make a function to return that status if
needed (like the "mysql_erro r()" function).
- Advantages: Can do a simple ===false test to determine success/failure.
In the case of a failure, simply use the "_error()" function to determine
what went wrong.
- Disadvantages: Another function to document and remember. Uses global
variables.
I'm leaning toward option 2.) (error lookup function), but I'm just
wondering: which is the "generally accepted PHP way of doing things" in a
situation like this?
Also, is there a generic term for those sort of "error lookup function"s?
I'm just a programming hobbyist, so I'm not up on *all* the lingo.
Thanks!
--
-- Rudy Fleminger
-- sp@mmers.and.ev il.ones.will.bo w-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
First, the return value of the function, consisting of some text. Second,
it should convey an "error status", which, could be either a simple
"success", or a number of levels of failure.
(For the record, it's a logon script indicating success/failure, but I'll
probably use this elsewhere.)
The way I see it, I have a couple options, maybe more:
1.) Return an array. The first element is the return value, the second is
the status code.
- Advantages: No global variables used. No "status check" functions.
- Disadvantages: Can't use a simple "if (function())" call to determine
success/failure, since it will always return "true". Need to deal with a
structure (array) instead of a simple variable.
2.) Return the string on success, or false on failure. Set a global
variable to the exit status, and make a function to return that status if
needed (like the "mysql_erro r()" function).
- Advantages: Can do a simple ===false test to determine success/failure.
In the case of a failure, simply use the "_error()" function to determine
what went wrong.
- Disadvantages: Another function to document and remember. Uses global
variables.
I'm leaning toward option 2.) (error lookup function), but I'm just
wondering: which is the "generally accepted PHP way of doing things" in a
situation like this?
Also, is there a generic term for those sort of "error lookup function"s?
I'm just a programming hobbyist, so I'm not up on *all* the lingo.
Thanks!
--
-- Rudy Fleminger
-- sp@mmers.and.ev il.ones.will.bo w-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Comment