libphonenumber\PhoneNumber::mergeFrom PHP Method

mergeFrom() public method

Merges the information from another phone number into this phone number.
public mergeFrom ( PhoneNumber $other ) : PhoneNumber
$other PhoneNumber The phone number to copy.
return PhoneNumber This PhoneNumber instance, for chaining method calls.
    public function mergeFrom(PhoneNumber $other)
    {
        if ($other->hasCountryCode()) {
            $this->setCountryCode($other->getCountryCode());
        }
        if ($other->hasNationalNumber()) {
            $this->setNationalNumber($other->getNationalNumber());
        }
        if ($other->hasExtension()) {
            $this->setExtension($other->getExtension());
        }
        if ($other->hasItalianLeadingZero()) {
            $this->setItalianLeadingZero($other->isItalianLeadingZero());
        }
        if ($other->hasNumberOfLeadingZeros()) {
            $this->setNumberOfLeadingZeros($other->getNumberOfLeadingZeros());
        }
        if ($other->hasRawInput()) {
            $this->setRawInput($other->getRawInput());
        }
        if ($other->hasCountryCodeSource()) {
            $this->setCountryCodeSource($other->getCountryCodeSource());
        }
        if ($other->hasPreferredDomesticCarrierCode()) {
            $this->setPreferredDomesticCarrierCode($other->getPreferredDomesticCarrierCode());
        }
        return $this;
    }

Usage Example

 public function testFormatNumberWithExtension()
 {
     $nzNumber = new PhoneNumber();
     $nzNumber->mergeFrom(self::$nzNumber)->setExtension("1234");
     // Uses default extension prefix:
     $this->assertEquals("03-331 6005 ext. 1234", $this->phoneUtil->format($nzNumber, PhoneNumberFormat::NATIONAL));
     // Uses RFC 3966 syntax.
     $this->assertEquals("+64-3-331-6005;ext=1234", $this->phoneUtil->format($nzNumber, PhoneNumberFormat::RFC3966));
     // Extension prefix overridden in the territory information for the US:
     $usNumberWithExtension = new PhoneNumber();
     $usNumberWithExtension->mergeFrom(self::$usNumber)->setExtension("4567");
     $this->assertEquals("650 253 0000 extn. 4567", $this->phoneUtil->format($usNumberWithExtension, PhoneNumberFormat::NATIONAL));
 }
All Usage Examples Of libphonenumber\PhoneNumber::mergeFrom