Opened 2 years ago

Last modified 2 years ago

#16471 new enhancement

Support default values for non-existant query vars in get_query_var() et al

Reported by: hakre Owned by:
Priority: normal Milestone: Awaiting Review
Component: General Version: 3.0
Severity: normal Keywords: has-patch
Cc: mikeschinkel@…

Description

When using get_query_var($var) or $GLOBALS['wp']->get($var) and $var is the name of an unexistant query variable, those functions will return an empty string.

Next to that there is no function that provides information about whether or not a specific query variable has been set.

I therefore suggest to make both functions able to optionally return a chooseable default fallback value then the empty string we have.

Attachments (1)

16471.patch (979 bytes) - added by hakre 2 years ago.

Download all attachments as: .zip

Change History (4)

hakre2 years ago

The attached patch now allows easier checking if certain values have been set (not being null in PHP):

$var_test = get_query_var('test', null);
if (!isset($var_test)) {
    throw new BadMethodCallException ('Invalid request. Test parameter not set.');
}

or making use of a predefined, default value more easily:

$days = get_query_var('days', 7);

+1. Similar to get_option().

  • Cc mikeschinkel@… added
Note: See TracTickets for help on using tickets.