devel:request_vars
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
devel:request_vars [2012-07-06 13:08] – created andi | devel:request_vars [2023-09-20 23:27] (current) – Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Accessing Request Variables ====== | ====== Accessing Request Variables ====== | ||
- | [[deveonly]] | ||
- | 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 11: | Line 10: | ||
If you want to access '' | If you want to access '' | ||
- | All the access function allow for a second parameter | + | Access |
- | A third parameter tells the function if an [[phpfn> | + | 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> | ||
===== 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.1341572914.txt.gz · Last modified: 2012-07-06 13:08 by andi