|
Posted by jussist@gmail.com on 01/10/07 09:57
Why don't we instead tweak the whole concept of magic numbers? And
don't use 0 there at all - but something else, 1&2, or.
static $STATE_ALREADY_COMPLETED = 1152; // Or whatever, was -1
static $STATE_COMPLETE_NOW = 1153; // Or whatever, was 0
switch($record->sub_page) {
case $STATE_ALREADY_COMPLETED:
$this->page = 6;
$error_message = '<center>You appear to have already completed the
form.</center>';
break;
case $STATE_COMPLETE_NOW:
$this->page = 5;
ff_query("UPDATE #__gateway_form_1 SET `sub_page`=-1 WHERE
userid=$my->id and `expiry_date` = '$expiry_date'");
break;
default:
do something else
}
This solution is totally independent of what is the meaning of '-1' or
'0'. If you need to add more states, with whatever meaning, would you
prefer doing:
case 3:
doSomething2();
case 4:
doAnotherFunkyThing();
case 5:
whatTheHeckDoesFiveMean();
or
case $STATE_DO_SOMETHING:
doSomething2();
case $STATE_GET_FUNKY:
doAnotherFunkyThing();
case $STATE_FURIOUS_FIVE:
...
[Back to original message]
|