You are here: Re: Zero and NULL (Stuckle) « PHP Programming Language « IT news, forums, messages
Re: Zero and NULL (Stuckle)

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:
...

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация