Call to a member function matcher() on a non-object in libphonenumber-for-php/PhoneNumberUtil.php on line 942
Opened this issue · 1 comments
michaellenahan commented
Hello, I'm using libphonenumber-for-php as part of the Drupal phone module (https://drupal.org/project/phone).
I got this error on a fairly standard looking number formatted as follows:
0054 11 2222 3333
Call to a member function matcher() on a non-object in libphonenumber-for-php/PhoneNumberUtil.php on line 942
The error occurs in this function:
PhoneNumberUtil->maybeStripNationalPrefixAndCarrierCode()
The work-around was to add an is_object() check so the matcher member function does not get called, but I don't know what the root cause of this problem could have been.
Code before:
$transformedNumber = $number;
$transformedNumber = substr_replace($transformedNumber, $prefixMatcher->replaceFirst($transformRule), 0, $numberLength);
if ($isViableOriginalNumber &&
!$nationalNumberRule->matcher($transformedNumber->toString())->matches()) {
return false;
}
Code after:
$transformedNumber = $number;
$transformedNumber = substr_replace($transformedNumber, $prefixMatcher->replaceFirst($transformRule), 0, $numberLength);
if ($isViableOriginalNumber && is_object($nationalNumberRule) &&
!$nationalNumberRule->matcher($transformedNumber->toString())->matches()) {
return false;
}
giggsey commented
Take a look at giggsey/libphonenumber-for-php#3 which also contains a similar fix to yours.