Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Call to a member function matcher() on a non-object in libphonenumber-for-php/PhoneNumberUtil.php on line 942 #27

Open
michaellenahan opened this issue Oct 28, 2013 · 1 comment

Comments

@michaellenahan
Copy link

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
Copy link

giggsey commented Nov 14, 2013

Take a look at giggsey/libphonenumber-for-php#3 which also contains a similar fix to yours.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants