Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the benefit of using filter_has_var() over isset()

Tags:

php

I'm a little confused with the benefit of using filter_has_var($_POST['id']) over isset($_POST['id']).

Can Somebody please tell me if it's simply an alias function?

like image 796
sreejith Avatar asked Feb 04 '11 14:02

sreejith


2 Answers

Not alot ;) According to the manual page for filter_has_var one user finds filter_has_var a little quicker. Also worth noting... filter_has_var isn't working on the live array ($_POST) but on the actual provided input... if you ever add/remove/update what's in that array you won't see those changes with a filter_has_var call (while isset will reflect the current state)

By the way the usage is filter_has_var(INPUT_POST,"id");

Update: Perhaps worth mentioning, filter_has_var was introduced in PHP 5.2.0 (somewhat new) while isset has been around for all of PHP4+5. Most servers keep up to date on this, but isset will always work (no one still runs PHP3 do they?)

like image 95
Rudu Avatar answered Sep 28 '22 02:09

Rudu


First of all, it's not

filter_has_var($_POST['id'])

It's

filter_has_var(INPUT_POST, 'id')

Secondly, it doesn't actually query the $_POST superglobal. It analyzes the request parameter that came in with the request, so it's a better method to use in case $_POST gets dirtied in some way by the PHP script.

like image 43
BoltClock Avatar answered Sep 28 '22 02:09

BoltClock