views:

31

answers:

2

Hi

I have this:

function boo($show_one = false){
  if(!show_one) return 1; else return 2;
}

how can I call boo like this:

boo(SHOW_ALL);

instead of boo(false). I see some native php function have parameters like that which make the code more easy to read

+4  A: 
define("SHOW_ALL", false);
define("SHOW_ONE", true);

would correspond to your code there. But I'd reccomend using numbers instead of booleans. What if next weeks you decide to have a SHOW_PAGINATED option?

Macha
oh i see now, they are called constants. tx.another question: do I have to worry about naming conflicts with default PHP defines?
Alex
I would imagine so. Don't do define("STRING", whatever). It might work, but it's a bad idea. Though most inbuilt constants are of the form MODULE_NAME_OF_CONSTANT iirc.
Macha
@Alex see the [Userland Naming Guide](http://de3.php.net/manual/en/userlandnaming.php)
Gordon
A: 
define('SHOW_ALL', true);

function boo($show_one = false){
  if(!$show_one) return 1; else return 2;
}

boo(SHOW_ALL);
powtac