Fatal uncaught error when testing a number.
tree28 opened this issue · 4 comments
Hello,
An observation –
When testing a number that does not have a correct format the following fatal error occurs. It would be beneficial to alter the code so that non-compliant numbers were returned with a usable error code or message. The return could be used to provide feedback back to the user, for example telling them that the number was invalid, while also preventing the fatal error from halting the system.
A reasonable change if this utility exists to do analysis on numbers from the wild.
The error –
Fatal error: Uncaught Error type: 0. Missing or invalid default region. thrown in /var/www/vendor/giggsey/libphonenumber-for-php/src/PhoneNumberUtil.php on line 1682
The code –
$phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$phoneNumberObject = $phoneNumberUtil->parse('a wild number',null);
An observation –
This seems to be best and maybe a usable example.
$phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$filter = array('us','au','gb');
for($i = 0; $i < count($filter); $i++)
{
$phoneNumberObject = $phoneNumberUtil->parse('a wild number',$filter[$i]);
if($phoneNumberUtil->getRegionCodeForNumber($phoneNumberObject))
{
$cciso2 = $phoneNumberUtil->getRegionCodeForNumber($phoneNumberObject);
break;
}
}
Thanks for the library – appreciate the work.