|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65024 filter_var bug?
Submitted: 2013-06-13 07:38 UTC Modified: 2013-06-13 14:15 UTC
From: jakquan at foxmail dot com Assigned:
Status: Not a bug Package: filter (PECL)
PHP Version: 5.3Git-2013-06-13 (snap) OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jakquan at foxmail dot com
New email:
PHP Version: OS:


 [2013-06-13 07:38 UTC] jakquan at foxmail dot com
the result returned by filter_var should be true,but it returned false when 
validate the email address "" using filter_var with the option 

Test script:
$address = '';
$valid = filter_var($address, FILTER_VALIDATE_EMAIL);
var_dump( $valid );

Expected result:
string(18) ""

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-13 07:39 UTC] jakquan at foxmail dot com
& my php version is old PHP 5.2.10p1.
 [2013-06-13 07:42 UTC]
-Status: Open +Status: Feedback
 [2013-06-13 07:42 UTC]
Please try using latest release bundled with 5.4 (or at least latest 5.3)
 [2013-06-13 07:48 UTC] jakquan at foxmail dot com
Our production php use the old one,Do you mean the latest version php fix the 
I found source code as below in my php:
void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
	 * The regex below is based on a regex by Michael Rushton.
	 * However, it is not identical.  I changed it to only consider 
	 * addresses as valid.  Michael's regex considers a@b a valid address
	 * which conflicts with section 2.3.5 of RFC 5321 which states that:
	 *   Only resolvable, fully-qualified domain names (FQDNs) are permitted
	 *   when domain names are used in SMTP.  In other words, names that can
	 *   be resolved to MX RRs or address (i.e., A or AAAA) RRs (as 
	 *   in Section 5) are permitted, as are CNAME RRs whose targets can be
	 *   resolved, in turn, to MX or address RRs.  Local nicknames or
	 *   unqualified names MUST NOT be used.
	 * This regex does not handle comments and folding whitespace.  While
	 * this is technically valid in an email address, these parts aren't
	 * actually part of the address itself.
	 * Michael's regex carries this copyright:
	 * Copyright © Michael Rushton 2009-10
	 * Feel free to use and redistribute this code. But please keep this 
copyright notice.
	const char regexp[] = "/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|

	pcre       *re = NULL;
	pcre_extra *pcre_extra = NULL;
	int preg_options = 0;
	int         ovector[150]; /* Needs to be a multiple of 3 */
	int         matches;

	/* The maximum length of an e-mail address is 320 octets, per RFC 2821. 
	if (Z_STRLEN_P(value) > 320) {

	re = pcre_get_compiled_regex((char *)regexp, &pcre_extra, &preg_options 
	if (!re) {
	matches = pcre_exec(re, NULL, Z_STRVAL_P(value), Z_STRLEN_P(value), 0, 
0, ovector, 3);

	/* 0 means that the vector is too small to hold all the captured 
substring offsets */
	if (matches < 0) {

 [2013-06-13 14:15 UTC]
-Status: Feedback +Status: Not a bug
 [2013-06-13 14:15 UTC]
I fixed this 3 or 4 years ago. Please use a more recent version.


php > $address = '';
php > $valid = filter_var($address, FILTER_VALIDATE_EMAIL);
php > var_dump( $valid );
string(18) ""
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 09 04:03:34 2021 UTC