From 71075dac88b9ccff6a7f1e1ce0e4f2e866f906df Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Wed, 21 Mar 2007 11:36:40 +0000 Subject: [PATCH] PMA_isValid(): added 'identical' as $type option --- libraries/core.lib.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/libraries/core.lib.php b/libraries/core.lib.php index 6d0a16f52..611ea8ff9 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -48,12 +48,22 @@ function PMA_ifSetOr(&$var, $default = null, $type = 'similar') * checks given $var against $type or $compare * * $type can be: - * - false: no type checking - * - 'scalar': integer, float, string or boolean - * - 'numeric': nay number repesentation - * - 'length': for any scalar with a string length > 0 + * - false : no type checking + * - 'scalar' : whether type of $var is integer, float, string or boolean + * - 'numeric' : whether type of $var is any number repesentation + * - '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 * + * + * // $_REQUEST['doit'] = true; + * PMA_isValid($_REQUEST['doit'], 'identical', 'true'); // false + * // $_REQUEST['doit'] = 'true'; + * PMA_isValid($_REQUEST['doit'], 'identical', 'true'); // true + * + * * @todo create some testsuites * @todo add some more var types like hex, bin, ...? * @uses is_scalar() @@ -81,6 +91,9 @@ function PMA_isValid(&$var, $type = 'length', $compare = null) // allow some aliaes of var types $type = strtolower($type); switch ($type) { + case 'identic' : + $type = 'identical'; + break; case 'len' : $type = 'length'; break; @@ -98,6 +111,10 @@ function PMA_isValid(&$var, $type = 'length', $compare = null) break; } + if ($type === 'identical') { + return $var === $compare; + } + // whether we should check against given $compare if ($type === 'similar') { switch (gettype($compare)) { @@ -112,7 +129,7 @@ function PMA_isValid(&$var, $type = 'length', $compare = null) default: $type = gettype($compare); } - } elseif ($type === 'identic') { + } elseif ($type === 'equal') { $type = gettype($compare); }