PMA_isValid(): added 'identical' as $type option
This commit is contained in:
@@ -48,12 +48,22 @@ function PMA_ifSetOr(&$var, $default = null, $type = 'similar')
|
|||||||
* checks given $var against $type or $compare
|
* checks given $var against $type or $compare
|
||||||
*
|
*
|
||||||
* $type can be:
|
* $type can be:
|
||||||
* - false: no type checking
|
* - false : no type checking
|
||||||
* - 'scalar': integer, float, string or boolean
|
* - 'scalar' : whether type of $var is integer, float, string or boolean
|
||||||
* - 'numeric': nay number repesentation
|
* - 'numeric' : whether type of $var is any number repesentation
|
||||||
* - 'length': for any scalar with a string length > 0
|
* - 'length' : whether type of $var is scalar with a string length > 0
|
||||||
|
* - 'similar' : whether type of $var is similar to type of $compare
|
||||||
|
* - 'equal' : whether type of $var is identical to type of $compare
|
||||||
|
* - 'identical' : whether $var is identical to $compare, not only the type!
|
||||||
* - or any other valid PHP variable type
|
* - or any other valid PHP variable type
|
||||||
*
|
*
|
||||||
|
* <code>
|
||||||
|
* // $_REQUEST['doit'] = true;
|
||||||
|
* PMA_isValid($_REQUEST['doit'], 'identical', 'true'); // false
|
||||||
|
* // $_REQUEST['doit'] = 'true';
|
||||||
|
* PMA_isValid($_REQUEST['doit'], 'identical', 'true'); // true
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
* @todo create some testsuites
|
* @todo create some testsuites
|
||||||
* @todo add some more var types like hex, bin, ...?
|
* @todo add some more var types like hex, bin, ...?
|
||||||
* @uses is_scalar()
|
* @uses is_scalar()
|
||||||
@@ -81,6 +91,9 @@ function PMA_isValid(&$var, $type = 'length', $compare = null)
|
|||||||
// allow some aliaes of var types
|
// allow some aliaes of var types
|
||||||
$type = strtolower($type);
|
$type = strtolower($type);
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case 'identic' :
|
||||||
|
$type = 'identical';
|
||||||
|
break;
|
||||||
case 'len' :
|
case 'len' :
|
||||||
$type = 'length';
|
$type = 'length';
|
||||||
break;
|
break;
|
||||||
@@ -98,6 +111,10 @@ function PMA_isValid(&$var, $type = 'length', $compare = null)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($type === 'identical') {
|
||||||
|
return $var === $compare;
|
||||||
|
}
|
||||||
|
|
||||||
// whether we should check against given $compare
|
// whether we should check against given $compare
|
||||||
if ($type === 'similar') {
|
if ($type === 'similar') {
|
||||||
switch (gettype($compare)) {
|
switch (gettype($compare)) {
|
||||||
@@ -112,7 +129,7 @@ function PMA_isValid(&$var, $type = 'length', $compare = null)
|
|||||||
default:
|
default:
|
||||||
$type = gettype($compare);
|
$type = gettype($compare);
|
||||||
}
|
}
|
||||||
} elseif ($type === 'identic') {
|
} elseif ($type === 'equal') {
|
||||||
$type = gettype($compare);
|
$type = gettype($compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user