#49665 [Opn->Csd]: bad example for filter_var() in documentation

From: Date: Fri, 25 Sep 2009 11:13:10 +0000
Subject: #49665 [Opn->Csd]: bad example for filter_var() in documentation
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2818@lists.php.net to get a copy of this message
ID: 49665 Updated by: salathe@php.net Reported By: alex dot schuch at gmx dot de -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: - PHP Version: Irrelevant New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2009-09-25 11:10:56] 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 08:33:19] 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- ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49665&edit=1

« previous php.doc.bugs (#2818) next »