php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50632 Return default value if var is undefined
Submitted: 2010-01-02 09:38 UTC Modified: 2010-01-03 22:58 UTC
Votes:7
Avg. Score:3.9 ± 1.8
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: gmblar+php at gmail dot com Assigned:
Status: Closed Package: Filter related
PHP Version: 5.3.1 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gmblar+php at gmail dot com
New email:
PHP Version: OS:

 

 [2010-01-02 09:38 UTC] gmblar+php at gmail dot com
Description:
------------
if $_GET['foo'] is undefined, filter functions return NULL instead of 
the default value defined in options.

Reproduce code:
---------------
<?php

$foo = filter_input(INPUT_GET, 'foo', FILTER_VALIDATE_INT, array(
    'flags' => FILTER_REQUIRE_SCALAR,
    'options' => array(
        'default' => 23,
        'min_range' => 5,
        'max_range' => 42
    )
));

var_dump($foo);

?>

Expected result:
----------------
int(23)

Actual result:
--------------
NULL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-03 22:58 UTC] svn@php.net
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=293051
Log: Fixed bug #50632 (filter_input() does not return default value if the variable does not exist)
 [2010-01-03 22:58 UTC] iliaa@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2010-01-05 12:25 UTC] svn@php.net
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=293144
Log: Added test case for bug #50632
 [2010-01-27 17:22 UTC] svn@php.net
Automatic comment from SVN on behalf of johannes
Revision: http://svn.php.net/viewvc/?view=revision&revision=294106
Log: merge r293051: Fixed bug #50632 (filter_input() does not return default value if
the variable does not exist) (iliaa)
 [2010-01-28 01:45 UTC] svn@php.net
Automatic comment from SVN on behalf of johannes
Revision: http://svn.php.net/viewvc/?view=revision&revision=294133
Log: merge r293144 - Added test case for bug #50632 (iliaa)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC