php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49665 bad example for filter_var() in documentation
Submitted: 2009-09-25 08:33 UTC Modified: 2009-09-25 11:13 UTC
From: alex dot schuch at gmx dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: -
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alex dot schuch at gmx dot de
New email:
PHP Version: OS:

 

 [2009-09-25 08:33 UTC] alex dot schuch at gmx dot de
Description:
------------
The example given at "http://www.php.net/manual/en/filter.examples.validation.php" makes people believe the sanitation always work that way, which is not the case.

The example should be like this:

if (($int_c = filter_var($int_c, FILTER_VALIDATE_INT, $options)) !== FALSE) {
    echo "This (int_c) integer is considered valid (between 0 and 3) and is $int_c.";
}

This is related to <http://bugs.php.net/bug.php?id=42136>.

Reproduce code:
---------------
<?php
$int_c = '4';
$options = array(
    'options' => array(
                      'min_range' => 0,
                      'max_range' => 3,
                      )
);
// [...]
$options['options']['default'] = 0; // has "1" in documentation
if ($int_c = filter_var($int_c, FILTER_VALIDATE_INT, $options)) {
    echo "This (int_c) integer is considered valid (between 0 and 3) and is $int_c.";
}
?>

Expected result:
----------------
This (int_c) integer is considered valid (between 0 and 3) and is 0.

Actual result:
--------------
-no output-

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-25 11:10 UTC] svn@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&revision=288748
Log: Strict comparison of filter_var return values in examples. Fixes #49665
 [2009-09-25 11:13 UTC] salathe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

I've added strict checking for FALSE in that particular example (where the filter might have returned 0 as a valid value but the if statement would have interpreted that as false giving no output). Docs reflect your suggested amendment.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 12:00:01 2026 UTC