From cd28ecb83ee7e5370089b511bf6465e0024e81a7 Mon Sep 17 00:00:00 2001 From: perrygeorget Date: Tue, 25 Dec 2012 09:53:19 -0800 Subject: [PATCH] Update PhoneNumberUtil.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If no region to unset is found by array_search, it returns false.  This is interpreted by unset as 0 causing the region code as index 0 to be lost. --- PhoneNumberUtil.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PhoneNumberUtil.php b/PhoneNumberUtil.php index a1c85b3..0f4eaa7 100644 --- a/PhoneNumberUtil.php +++ b/PhoneNumberUtil.php @@ -233,7 +233,11 @@ private function init($filePrefix) { foreach ($this->countryCallingCodeToRegionCodeMap as $regionCodes) { $this->supportedRegions = array_merge($this->supportedRegions, $regionCodes); } - unset($this->supportedRegions[array_search(self::REGION_CODE_FOR_NON_GEO_ENTITY, $this->supportedRegions)]); + $unsupportedRegionIndex = array_search(self::REGION_CODE_FOR_NON_GEO_ENTITY, $this->supportedRegions); + if ($unsupportedRegionIndex !== false) + { + unset($this->supportedRegions[$unsupportedRegionIndex]); + } $this->nanpaRegions = $this->countryCallingCodeToRegionCodeMap[self::NANPA_COUNTRY_CODE]; }