Well, if someone submitted a blank field, or a field containing "0", then empty() would regard it as empty.
Code: Select all
$a = array('foo' => 0);
var_dump(empty($a)); # => bool(false)
$a = array('foo' => '');
var_dump(empty($a)); # => bool(false)
$a = array('' => '');
var_dump(empty($a)); # => bool(false)
$a = array('');
var_dump(empty($a)); # => bool(false)
$a = array();
var_dump(empty($a)); # => bool(true)
I actually prefer
Code: Select all
if($_SERVER['REQUEST_METHOD'] == 'POST');
Because if the request method is post, then they're at least
trying to submit something, which your script should acknowledge imo.
The particulars of that argument might have merit. It's not something I've thought about before. At this time I don't have the motivation to go delving into the HTTP spec to find out which way is the most correct, reliable, and true to design. But, $_SERVER['REQUEST_METHOD'] == 'POST' certainly reads better than !empty($_POST), so I think I'll probably use that from now on.
But obviously this is all just personal preference

I am contemptuousness of leaving any decision to opinion where there is a reasonable alternative. People are idiots; they will aggressively believe nonsense if left to their own devices. What we are trying to achieve is that which is simple to understand and work with; these can be assessed relatively objectively, with a good approach.
Ego (the self and self-preservation) and familiarity (the patterning system of the mind) are the forces of opinion. If these can be removed then objectivity will emerge. Ego and familiarity may be allowed to return to settle on that which has been objectively discovered afterwards; their suspension is only required during times of discovery and assessment.
It is often obvious when another's ego is affecting a decision; affecting in favor produces a smile; affecting in opposition produces a frown. I try to cultivate any awareness of these occurring in myself and others, and adjust for them appropriately.
Putting familiarity aside is more challenging. Being familiar with nothing is akin to being comatose. You can, however, approximate familiarity with nothing by being all-knowing; omniscient. Fortunately you don't actually need to know
everything, merely, as much as can be reasonably attained, about, precisely, the task at hand.