Skip to main content
August 21, 2012
Answered

filter_has_var vs isset

  • August 21, 2012
  • 1 reply
  • 965 views

I am using the following to sanitize input prior to validating:

if(filter_has_var(INPUT_POST, "$var")) {

$sanitized = filter_input(INPUT_POST, '$var', FILTER_SANITIZE_STRING);

$_POST['$var'] = trim($sanitized);

Is it preferable to use filter_has_var() to check the input or isset()? Is there a difference and what is it?

Thank you in advance for any help.

This topic has been closed for replies.
Correct answer David_Powers

According to an anonymous note in the PHP documentation, filter_has_var() is slightly faster than isset(). I've no idea if that's accurate, but it hasn't been removed by the PHP documentation team, so it seems legitimate.

Other than that, there's no difference.

1 reply

David_Powers
David_PowersCorrect answer
Inspiring
August 25, 2012

According to an anonymous note in the PHP documentation, filter_has_var() is slightly faster than isset(). I've no idea if that's accurate, but it hasn't been removed by the PHP documentation team, so it seems legitimate.

Other than that, there's no difference.