Fix some minor bugs in global functions and add unit tests

This commit is contained in:
Kijin Sung 2016-03-16 10:09:48 +09:00
parent c64df413f5
commit f9ea115c19
2 changed files with 158 additions and 3 deletions

View file

@ -238,7 +238,7 @@ function starts_with($needle, $haystack, $case_sensitive = true)
}
else
{
!strncasecmp($needle, $haystack, strlen($needle));
return !strncasecmp($needle, $haystack, strlen($needle));
}
}
@ -452,8 +452,11 @@ if (!function_exists('hex2bin'))
*/
function tobool($input)
{
if (preg_match('/^(1|[ty].*|on|oui|si|vrai|aye)$/i', $input)) return true;
if (preg_match('/^(0|[fn].*|off)$/i', $input)) return false;
if (is_scalar($input))
{
if (preg_match('/^(1|[ty].*|on|ok.*oui|si|vrai|aye)$/i', $input)) return true;
if (preg_match('/^(0|[fn].*|off)$/i', $input)) return false;
}
return (bool)$input;
}