Test of $_POST Variable's Existance Fails if Value=0

I always believed that if I had a test like this in a server action:

null

Then the condition will be false if the $_POST variable is null, and true in all other cases.

However this example I am working with also returns false if the $_POST variable has the value of 0.

Did I misunderstand how this works, or is it a bug? I am still on 3.9.3.

How can I structure the test so that it will return false ONLY when the $_POST variable is null?

Actually not a bug – a zero is considered “falsey”. That’s why we can interchange zero’s and false, along with one and true.

This should work for you:

$_POST.final_instalment_days_before || $_POST.final_instalment_days_before == 0
2 Likes

Thanks Ken!