but how will it know that im sending the defined constant as a parameter
Consider a function foo() that accepts an argument $arg
If FOO_ADD is set, it adds $arg to itself.
If FOO_MUL is set, it multiplies $arg by itself.
If both are set, it first adds $arg to itself, then multiplies the new result by itself.
If FOO_NEG is set, then the result is negated before being returned.
define("FOO_DEF", 0);
define("FOO_ADD", 1);
define("FOO_MUL", 2);
define("FOO_NEG", 4);
function foo($arg, $flag = FOO_DEF) {
if ($flag&FOO_ADD) {
$arg += $arg;
}
if ($flag&FOO_MUL) {
$arg *= $arg;
}
if ($flag&FOO_NEG) {
$arg = -$arg;
}
return $arg;
}
The idea here is to use the individual bits in $flag.
As such, the various FOO_* values are set in multiplies of 2 (thereabouts).
So to set both FOO_ADD and FOO_MUL, one would use FOO_ADD|FOO_MUL for the flag.
To do that and negate the final value as well, one would use FOO_ADD|FOO_MUL|FOO_NEG
Also, since a default value for the flag (FOO_DEF) is used as a default argument, one can call foo() using only a single argument - foo() here will just return the argument passed to it untouched.