devel:request_vars
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devel:request_vars [2015-10-09 22:54] – [Accessing Request Variables] turnermm | devel:request_vars [2023-09-20 23:27] (current) – Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Accessing Request Variables ====== | ====== Accessing Request Variables ====== | ||
- | Available since 2012-09-10 "Adora Belle" | ||
- | DokuWiki does not prohibit access to the '' | + | DokuWiki does not prohibit access to the '' |
The class gives you type safe access to the request variables, makes sure they are correctly initialized and allows you to set defaults. | The class gives you type safe access to the request variables, makes sure they are correctly initialized and allows you to set defaults. | ||
Line 10: | Line 9: | ||
If you want to access '' | If you want to access '' | ||
+ | |||
+ | Access to '' | ||
All the access functions allow for a second parameter to set a default value. This value will be returned when the variable was not set or had the wrong type (eg. an expected integer was an array instead). All access functions have reasonable defaults matching the type of the function. Eg. '' | All the access functions allow for a second parameter to set a default value. This value will be returned when the variable was not set or had the wrong type (eg. an expected integer was an array instead). All access functions have reasonable defaults matching the type of the function. Eg. '' | ||
- | A third parameter tells the function if an [[phpfn> | + | A third parameter tells the function if an [[phpfn> |
===== Examples ===== | ===== Examples ===== | ||
- | Here are a couple of examples to give you an idea how the Input class works. For detailed info, please refer to [[xref> | + | Here are a couple of examples to give you an idea how the Input class works. For detailed info, please refer to [[xref> |
<code php> | <code php> | ||
global $INPUT; | global $INPUT; | ||
- | $_REQUEST = array(' | + | $_REQUEST = [' |
var_dump($INPUT-> | var_dump($INPUT-> | ||
Line 42: | Line 43: | ||
// array(0) { | // array(0) { | ||
// } | // } | ||
+ | |||
+ | var_dump($INPUT-> | ||
+ | // bool(true) | ||
- | $_POST = array(' | + | $_POST = [' |
// now accessing $_POST and trying the third parameter | // now accessing $_POST and trying the third parameter | ||
Line 59: | Line 63: | ||
var_dump($INPUT-> | var_dump($INPUT-> | ||
// int(-1) | // int(-1) | ||
+ | |||
+ | |||
+ | $_SERVER | ||
+ | |||
+ | var_dump($INPUT-> | ||
+ | // string(8) " | ||
</ | </ |
devel/request_vars.1444424062.txt.gz · Last modified: 2015-10-09 22:54 by turnermm