From 1c84017d23a40de0595afd2352ccc0b3935b7dd1 Mon Sep 17 00:00:00 2001 From: plegall Date: Fri, 16 Dec 2011 20:57:55 +0000 Subject: 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 --- include/dblayer/functions_mysql.inc.php | 19 +++++++++++-------- 1 file 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; } /** -- cgit v1.2.3