Moodle PHP Documentation 4.5
Moodle 4.5.5+ (Build: 20250711) (ce34e8ff087)
libphonenumber\PhoneNumber Class Reference
Inheritance diagram for libphonenumber\PhoneNumber:

Public Member Functions

 __serialize ()
 
 __toString ()
 Returns a string representation of this phone number.
 
 __unserialize (array $data)
 
 clear ()
 Clears this phone number.
 
 clearCountryCode ()
 Clears the country code of this phone number.
 
 clearCountryCodeSource ()
 Clears the country code source of this phone number.
 
 clearExtension ()
 Clears the extension of this phone number.
 
 clearItalianLeadingZero ()
 Clears the italian leading zero information of this phone number.
 
 clearNationalNumber ()
 Clears the national number of this phone number.
 
 clearNumberOfLeadingZeros ()
 Clears the number of leading zeros of this phone number.
 
 clearPreferredDomesticCarrierCode ()
 Clears the preferred domestic carrier code of this phone number.
 
 clearRawInput ()
 Clears the raw input of this phone number.
 
 equals (PhoneNumber $other)
 Returns whether this phone number is equal to another.
 
 getCountryCode ()
 Returns the country code of this phone number.
 
 getCountryCodeSource ()
 Returns the country code source of this phone number.
 
 getExtension ()
 Returns the extension of this phone number.
 
 getNationalNumber ()
 Returns the national number of this phone number.
 
 getNumberOfLeadingZeros ()
 Returns the number of leading zeros of this phone number.
 
 getPreferredDomesticCarrierCode ()
 Returns the preferred domestic carrier code of this phone number.
 
 getRawInput ()
 Returns the raw input of this phone number.
 
 hasCountryCode ()
 Returns whether this phone number has a country code set.
 
 hasCountryCodeSource ()
 Returns whether this phone number has a country code source.
 
 hasExtension ()
 Returns whether this phone number has an extension set.
 
 hasItalianLeadingZero ()
 Returns whether this phone number has the italian leading zero information set.
 
 hasNationalNumber ()
 Returns whether this phone number has a national number set.
 
 hasNumberOfLeadingZeros ()
 Returns whether this phone number has a number of leading zeros set.
 
 hasPreferredDomesticCarrierCode ()
 Returns whether this phone number has a preferred domestic carrier code.
 
 hasRawInput ()
 Returns whether this phone number has a raw input.
 
 isItalianLeadingZero ()
 Returns whether this phone number uses an italian leading zero.
 
 mergeFrom (PhoneNumber $other)
 Merges the information from another phone number into this phone number.
 
 serialize ()
 @inheritDoc
 
 setCountryCode (int $value)
 Sets the country code of this phone number.
 
 setCountryCodeSource (int $value)
 Sets the country code source of this phone number.
 
 setExtension (string $value)
 Sets the extension of this phone number.
 
 setItalianLeadingZero (bool $value)
 Sets whether this phone number uses an italian leading zero.
 
 setNationalNumber (string $value)
 Sets the national number of this phone number.
 
 setNumberOfLeadingZeros (int $value)
 Sets the number of leading zeros of this phone number.
 
 setPreferredDomesticCarrierCode (string $value)
 Sets the preferred domestic carrier code of this phone number.
 
 setRawInput (string $value)
 Sets the raw input of this phone number.
 
 unserialize ($data)
 @inheritDoc
 

Protected Attributes

int $countryCode = null
 
int $countryCodeSource = CountryCodeSource::UNSPECIFIED
 The source from which the country_code is derived.
 
string $extension = null
 Extension is not standardized in ITU recommendations, except for being defined as a series of numbers with a maximum length of 40 digits.
 
bool $hasNumberOfLeadingZeros = false
 Whether this phone number has a number of leading zeros set.
 
bool $italianLeadingZero = null
 In some countries, the national (significant) number starts with one or more "0"s without this being a national prefix or trunk code of some kind.
 
string $nationalNumber = null
 National (significant) Number is defined in International Telecommunication Union (ITU) Recommendation E.164.
 
int $numberOfLeadingZeros = 1
 The number of leading zeros of this phone number.
 
string $preferredDomesticCarrierCode = null
 The carrier selection code that is preferred when calling this phone number domestically.
 
string $rawInput = null
 This field is used to store the raw input string containing phone numbers before it was canonicalized by the library.
 

Member Function Documentation

◆ __serialize()

libphonenumber\PhoneNumber::__serialize ( )
Return values
array{?int,?string,?string,?bool,int,?string,int,?string}

◆ __toString()

libphonenumber\PhoneNumber::__toString ( )

Returns a string representation of this phone number.

Return values
string

◆ __unserialize()

libphonenumber\PhoneNumber::__unserialize ( array $data)
Parameters
array{int,?string,?string,?bool,int,?string,int,?string}$data

◆ clear()

libphonenumber\PhoneNumber::clear ( )

Clears this phone number.

This effectively resets this phone number to the state of a new instance.

Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ clearCountryCode()

libphonenumber\PhoneNumber::clearCountryCode ( )

Clears the country code of this phone number.

Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ clearCountryCodeSource()

libphonenumber\PhoneNumber::clearCountryCodeSource ( )

Clears the country code source of this phone number.

Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ clearExtension()

libphonenumber\PhoneNumber::clearExtension ( )

Clears the extension of this phone number.

Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ clearItalianLeadingZero()

libphonenumber\PhoneNumber::clearItalianLeadingZero ( )

Clears the italian leading zero information of this phone number.

Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ clearNationalNumber()

libphonenumber\PhoneNumber::clearNationalNumber ( )

Clears the national number of this phone number.

Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ clearNumberOfLeadingZeros()

libphonenumber\PhoneNumber::clearNumberOfLeadingZeros ( )

Clears the number of leading zeros of this phone number.

Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ clearPreferredDomesticCarrierCode()

libphonenumber\PhoneNumber::clearPreferredDomesticCarrierCode ( )

Clears the preferred domestic carrier code of this phone number.

Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ clearRawInput()

libphonenumber\PhoneNumber::clearRawInput ( )

Clears the raw input of this phone number.

Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ equals()

libphonenumber\PhoneNumber::equals ( PhoneNumber $other)

Returns whether this phone number is equal to another.

Parameters
PhoneNumber$otherThe phone number to compare.
Return values
boolTrue if the phone numbers are equal, false otherwise.

◆ getCountryCode()

libphonenumber\PhoneNumber::getCountryCode ( )

Returns the country code of this phone number.

Return values
int|nullThe country code, or null if not set.

◆ getCountryCodeSource()

libphonenumber\PhoneNumber::getCountryCodeSource ( )

Returns the country code source of this phone number.

Return values
int|nullA CountryCodeSource constant, or null if not set.

◆ getExtension()

libphonenumber\PhoneNumber::getExtension ( )

Returns the extension of this phone number.

Return values
string|nullThe extension, or null if not set.

◆ getNationalNumber()

libphonenumber\PhoneNumber::getNationalNumber ( )

Returns the national number of this phone number.

Return values
string|nullThe national number, or null if not set.

◆ getNumberOfLeadingZeros()

libphonenumber\PhoneNumber::getNumberOfLeadingZeros ( )

Returns the number of leading zeros of this phone number.

Return values
intThe number of leading zeros.

◆ getPreferredDomesticCarrierCode()

libphonenumber\PhoneNumber::getPreferredDomesticCarrierCode ( )

Returns the preferred domestic carrier code of this phone number.

Return values
string|nullThe preferred domestic carrier code, or null if not set.

◆ getRawInput()

libphonenumber\PhoneNumber::getRawInput ( )

Returns the raw input of this phone number.

Return values
string|nullThe raw input, or null if not set.

◆ hasCountryCode()

libphonenumber\PhoneNumber::hasCountryCode ( )

Returns whether this phone number has a country code set.

Return values
boolTrue if a country code is set, false otherwise.

◆ hasCountryCodeSource()

libphonenumber\PhoneNumber::hasCountryCodeSource ( )

Returns whether this phone number has a country code source.

Return values
boolTrue if a country code source is set, false otherwise.

◆ hasExtension()

libphonenumber\PhoneNumber::hasExtension ( )

Returns whether this phone number has an extension set.

Return values
boolTrue if an extension is set, false otherwise.

◆ hasItalianLeadingZero()

libphonenumber\PhoneNumber::hasItalianLeadingZero ( )

Returns whether this phone number has the italian leading zero information set.

Return values
bool

◆ hasNationalNumber()

libphonenumber\PhoneNumber::hasNationalNumber ( )

Returns whether this phone number has a national number set.

Return values
boolTrue if a national number is set, false otherwise.

◆ hasNumberOfLeadingZeros()

libphonenumber\PhoneNumber::hasNumberOfLeadingZeros ( )

Returns whether this phone number has a number of leading zeros set.

Return values
boolTrue if a number of leading zeros is set, false otherwise.

◆ hasPreferredDomesticCarrierCode()

libphonenumber\PhoneNumber::hasPreferredDomesticCarrierCode ( )

Returns whether this phone number has a preferred domestic carrier code.

Return values
boolTrue if a preferred domestic carrier code is set, false otherwise.

◆ hasRawInput()

libphonenumber\PhoneNumber::hasRawInput ( )

Returns whether this phone number has a raw input.

Return values
boolTrue if a raw input is set, false otherwise.

◆ isItalianLeadingZero()

libphonenumber\PhoneNumber::isItalianLeadingZero ( )

Returns whether this phone number uses an italian leading zero.

Return values
bool|nullTrue if it uses an italian leading zero, false if it does not, null if not set.

◆ mergeFrom()

libphonenumber\PhoneNumber::mergeFrom ( PhoneNumber $other)

Merges the information from another phone number into this phone number.

Parameters
PhoneNumber$otherThe phone number to copy.
Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ setCountryCode()

libphonenumber\PhoneNumber::setCountryCode ( int $value)

Sets the country code of this phone number.

Parameters
int$valueThe country code.
Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ setCountryCodeSource()

libphonenumber\PhoneNumber::setCountryCodeSource ( int $value)

Sets the country code source of this phone number.

Parameters
int$valueA CountryCodeSource constant.
Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ setExtension()

libphonenumber\PhoneNumber::setExtension ( string $value)

Sets the extension of this phone number.

Parameters
string$valueThe extension.
Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ setItalianLeadingZero()

libphonenumber\PhoneNumber::setItalianLeadingZero ( bool $value)

Sets whether this phone number uses an italian leading zero.

Parameters
bool$valueTrue to use italian leading zero, false otherwise.
Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ setNationalNumber()

libphonenumber\PhoneNumber::setNationalNumber ( string $value)

Sets the national number of this phone number.

Parameters
string$valueThe national number.
Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ setNumberOfLeadingZeros()

libphonenumber\PhoneNumber::setNumberOfLeadingZeros ( int $value)

Sets the number of leading zeros of this phone number.

Parameters
int$valueThe number of leading zeros.
Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ setPreferredDomesticCarrierCode()

libphonenumber\PhoneNumber::setPreferredDomesticCarrierCode ( string $value)

Sets the preferred domestic carrier code of this phone number.

Parameters
string$valueThe preferred domestic carrier code.
Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

◆ setRawInput()

libphonenumber\PhoneNumber::setRawInput ( string $value)

Sets the raw input of this phone number.

Parameters
string$valueThe raw input.
Return values
PhoneNumberThis PhoneNumber instance, for chaining method calls.

Member Data Documentation

◆ $countryCodeSource

int libphonenumber\PhoneNumber::$countryCodeSource = CountryCodeSource::UNSPECIFIED
protected

The source from which the country_code is derived.

This is not set in the general parsing method, but in the method that parses and keeps raw_input. New fields could be added upon request.

See also
CountryCodeSource

This must be one of the CountryCodeSource constants.

◆ $extension

string libphonenumber\PhoneNumber::$extension = null
protected

Extension is not standardized in ITU recommendations, except for being defined as a series of numbers with a maximum length of 40 digits.

It is defined as a string here to accommodate for the possible use of a leading zero in the extension (organizations have complete freedom to do so, as there is no standard defined). However, only ASCII digits should be stored here.

◆ $italianLeadingZero

bool libphonenumber\PhoneNumber::$italianLeadingZero = null
protected

In some countries, the national (significant) number starts with one or more "0"s without this being a national prefix or trunk code of some kind.

For example, the leading zero in the national (significant) number of an Italian phone number indicates the number is a fixed-line number. There have been plans to migrate fixed-line numbers to start with the digit two since December 2000, but it has not happened yet. See http://en.wikipedia.org/wiki/%2B39 for more details.

These fields can be safely ignored (there is no need to set them) for most countries. Some limited number of countries behave like Italy - for these cases, if the leading zero(s) of a number would be retained even when dialling internationally, set this flag to true, and also set the number of leading zeros.

Clients who use the parsing functionality of the i18n phone number libraries will have these fields set if necessary automatically.

◆ $nationalNumber

string libphonenumber\PhoneNumber::$nationalNumber = null
protected

National (significant) Number is defined in International Telecommunication Union (ITU) Recommendation E.164.

It is a language/country-neutral representation of a phone number at a country level. For countries which have the concept of an "area code" or "national destination code", this is included in the National (significant) Number. Although the ITU says the maximum length should be 15, we have found longer numbers in some countries e.g. Germany.

Note that the National (significant) Number does not contain the National(trunk) prefix.

◆ $preferredDomesticCarrierCode

string libphonenumber\PhoneNumber::$preferredDomesticCarrierCode = null
protected

The carrier selection code that is preferred when calling this phone number domestically.

This also includes codes that need to be dialed in some countries when calling from landlines to mobiles or vice versa. For example, in Columbia, a "3" needs to be dialed before the phone number itself when calling from a mobile phone to a domestic landline phone and vice versa.

Note this is the "preferred" code, which means other codes may work as well.

◆ $rawInput

string libphonenumber\PhoneNumber::$rawInput = null
protected

This field is used to store the raw input string containing phone numbers before it was canonicalized by the library.

For example, it could be used to store alphanumerical numbers such as "1-800-GOOG-411".


The documentation for this class was generated from the following file: