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
This commit is contained in:
plegall 2011-12-16 20:57:55 +00:00
parent 1ea0155ad7
commit 1c84017d23

View file

@ -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;
}
/**