Fix toBool() and add more test cases

This commit is contained in:
Kijin Sung 2017-04-08 22:02:03 +09:00
parent f73580945d
commit 8147044802
2 changed files with 10 additions and 2 deletions

View file

@ -508,8 +508,8 @@ function tobool($input)
{
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;
if (preg_match('/^(?:1|[ty].*|on|ok.*|oui|si|vrai|aye)$/i', $input)) return true;
if (preg_match('/^(?:0|[fn].*|off|out)$/i', $input)) return false;
}
return (bool)$input;
}