aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2011-12-16 20:57:55 +0000
committerplegall <plg@piwigo.org>2011-12-16 20:57:55 +0000
commit1c84017d23a40de0595afd2352ccc0b3935b7dd1 (patch)
tree3f36e09300ead9debd8da3424d7421807178c778
parent1ea0155ad768dc7dd58e75a46d44865c6db03989 (diff)
better get_boolean function: able to detect "0" as false, (bool)false as false
and (int)0 as false. git-svn-id: http://piwigo.org/svn/trunk@12752 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--include/dblayer/functions_mysql.inc.php19
1 files changed, 11 insertions, 8 deletions
diff --git a/include/dblayer/functions_mysql.inc.php b/include/dblayer/functions_mysql.inc.php
index 785e588e0..9230af473 100644
--- a/include/dblayer/functions_mysql.inc.php
+++ b/include/dblayer/functions_mysql.inc.php
@@ -634,17 +634,20 @@ function get_enums($table, $field)
return $options;
}
-// get_boolean transforms a string to a boolean value. If the string is
-// "false" (case insensitive), then the boolean value false is returned. In
-// any other case, true is returned.
-function get_boolean( $string )
+/**
+ * Smartly checks if a variable is equivalent to true or false
+ *
+ * @param mixed input
+ * @return bool
+ */
+function get_boolean($input)
{
- $boolean = true;
- if ( 'false' == strtolower($string) )
+ if ('false' === strtolower($input))
{
- $boolean = false;
+ return false;
}
- return $boolean;
+
+ return (bool)$input;
}
/**