What is preferred isset($_POST['start_time'])
or @$_POS开发者_开发知识库T['start_time']
Neither.
isset
is "this exists and has a value", and that's not always what you want.
Consider array_key_exists
instead:
if(array_key_exists('foo', $_POST)) {
// code in here will operate if the key exists
// and can do whatever it needs with the value.
}
Too annoying? Also consider filter_input
, with the appropriate INPUT_POST
or INPUT_GET
flag. Shorter, neater, built-in validation, and no notices about missing keys.
$foo = filter_input(INPUT_POST, 'foo', FILTER_SANITIZE_NUMBER_INT);
Suppressing errors is not at all a good idea. I prefer using isset()
精彩评论