davideme / libphonenumber-for-PHP

PHP version of Google's phone number handling library
125 stars 71 forks source link

Avoid unsetting US as supported region #15

Closed jarseneault closed 7 years ago

jarseneault commented 11 years ago

The demo.php code, if run for a US phone number with a US region, fails with

Error type: 0. Missing or invalid default region.

because of the following line in PhoneNumberUtil::init:

unset($this->supportedRegions[array_search(self::REGION_CODE_FOR_NON_GEO_ENTITY, $this->supportedRegions)]);

The array_search returns false, which is coerced to 0 for the unset, which happens to correspond to the US region.

The attached commit prevents this behavior, but I'm not sure what you were trying to do here. My guess is that you were attempting to check against countryCallingCodeToRegionCodeMap instead of supportedRegions. If so, feel free to change. Thanks! Please let me know if I was misunderstanding something.

GuillaumeM69 commented 11 years ago

Thank You for this bug fix :+1:

travisemslander commented 11 years ago

I ran into this same issue when trying to learn how to use the library. Very confusing and thought I was just using it wrong as US appeared to be in the code. Any reason this hasn't been merged in?

adishua commented 11 years ago

Thanks!

thederrickbrown commented 8 years ago

Thank You for this fix!!

jarseneault commented 7 years ago

Author appears to be unreachable. Closing.