note 113698 added to function.filter-var

From: Date: Mon, 18 Nov 2013 10:23:25 +0000
Subject: note 113698 added to function.filter-var
Groups: php.notes 
Request: Send a blank email to php-notes+get-197553@lists.php.net to get a copy of this message
It is important to note that though the data type of the first parameter of the function is stated as "mixed", this is only one half of the truth. While it accepts any data type, the first parameter will always be cast to string before being validated or sanitized. It seems that this function was designed strictly to be used on user input strings. For example: from an online-form. When using it for anything other than that, you may see issues. So read the documentation very carefully! Especially note that there is an (to date) unresolved issue (#49510) concerning the Boolean filter while using the FILTER_NULL_ON_FAILURE flag. Note that both (string) FALSE and FALSE are not recognized as boolean values and will return NULL (not FALSE as you might expect). I thus personally suggest that (to date) the best way to take the filter_var()-functions beyond their original purpose (and allow future extension and customization) is to wrap them in your own classes. This will allow you to work-around unexpected behavior on non-string input and add your custom checks, or back-port filters or sanitizers that may be added in later versions of PHP. (Especially since PHP currently still lacks filters and sanitizers for some of the more exotic HTML5 input types, like "color". Thus there actually is a chance that we may see a need for custom filters or backports at some point in the future.) ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/function.filter-var.php Edit -- https://master.php.net/note/edit/113698 Del: integrated -- https://master.php.net/note/delete/113698/integrated Del: useless -- https://master.php.net/note/delete/113698/useless Del: bad code -- https://master.php.net/note/delete/113698/bad+code Del: spam -- https://master.php.net/note/delete/113698/spam Del: non-english -- https://master.php.net/note/delete/113698/non-english Del: in docs -- https://master.php.net/note/delete/113698/in+docs Del: other reasons-- https://master.php.net/note/delete/113698 Reject -- https://master.php.net/note/reject/113698 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197553) next »