When you have optional arguments that can have different types, which value is most suited to point out that the argument should not be taken into consideration? False or Null?
4 Answers
null
is the value used to represent "no value", whereas false
means "no", "bad", "unsuccessful", "don't" etc.
Therefore: null
.

- 510,633
- 85
- 743
- 889
For optional arguments use null
(generally).
Use null, if you need to differentiate between boolean values (true
/false
) and nothing (null
). On the other hand if you don't need to check for not-set argument and you are using boolean variable then I'd go for false
.

- 27,184
- 6
- 59
- 66
For me this depends on what I'm going to do with the value of said argument...
I am writing a database function where I can have default values as NULL
function somedbfunc($id = NULL, $column1 = NULL)
If these values are null my function may insert a blank record..
If I need to stop my function because of a non argument I may use FALSE
function blah($this = FALSE, $that = FALSE)
{
if ( ! $this || ! $that)
{
return FALSE;
....
So I am saying that both are totally valid, but it depends on the situation you find yourself in.

- 10,384
- 21
- 34
As you are saying that you want to tell the "optional arguments" "not be taken into consideration", I will go for null
. False
is explicitly saying "no" to the recipient. which is a valid input.

- 1,114
- 7
- 12