Skip to content

Commit 8f8cdc0

Browse files
committed
Added alias and recursive searching for parameter names
1 parent 39e1fff commit 8f8cdc0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

getvar.php.inc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ class getvar implements ArrayAccess {
2525

2626

2727

28-
public function __invoke($name=false, $flags=false) {
28+
public function __invoke($name=false, $flags=false, $recurse=false) {
2929
if ($flags === false) $flags = $this->default;
3030

31+
//RECURSIVE SEARCH
32+
if (is_array($name)) {
33+
foreach ($name as $item) {
34+
$value = $this($item, $flags, true);
35+
if (!is_null($value)) break;
36+
}
37+
}
38+
3139
//ATTEMPT TO GET THE VALUE FROM POST
32-
if (!($flags & _GETVAR_NOPOST)) {
40+
if (!isset($value) && !($flags & _GETVAR_NOPOST)) {
3341
if (is_bool($name)) return $this->post($name);
3442

3543
if ($this->type() === 'application/json') {
@@ -50,8 +58,11 @@ class getvar implements ArrayAccess {
5058
if (isset($_GET[$name])) $value = $_GET[$name];
5159
}
5260

61+
//HANDLE RECURSIVE SEARCHING
62+
if (!isset($value) && $recurse) return NULL;
63+
5364
//VALUE NOT FOUND
54-
if (!isset($value) || $value === '') {
65+
if (!isset($value) || is_null($value) || $value === '') {
5566
return ($flags & _GETVAR_NULL) ? NULL : '';
5667
}
5768

0 commit comments

Comments
 (0)