phone-number-bundle icon indicating copy to clipboard operation
phone-number-bundle copied to clipboard

Extensions Are Silently Dropped

Open kiler129 opened this issue 6 years ago • 4 comments

Problem

While working with phone numbers I discovered that phone numbers aren't handled properly when they contain extension. This is related to https://github.com/giggsey/libphonenumber-for-php/issues/255, since PhoneNumberType internally calls PhoneNumberUtil::format() while saving and PhoneNumberUtil::parse() while reading.

Solution

Maybe a better way would be to serialize and unserialize the object instead to prevent loosing data, since PhoneNumber intentionally implements \Serializable. Of course at this point it has to be done as a separate DBAL type to prevent BC issues with old data saved in DB.

I can prepare patch if you like, however I'm not sure is that what you want to do.

Workaround

Currently the easiest workaround for the issue while using anemic entities is to use two fields in entity, say phone & phoneExt and make getPhone() add extension to the object from phoneExt() and setPhone() to extract extension to a separate field.

kiler129 avatar Jun 07 '18 14:06 kiler129

Why not store the PhoneNumberFormat::RFC3966 ? This stores the extension as well. Is there data it loses compared to E164? I'm wondering if we could even configure the doctrine type to allow us to pick the DB format?

gnat42 avatar Oct 01 '18 19:10 gnat42

@gnat42 Mostly useless overhead of tel:. However we actually did that and we store RFC-3966 format with custom doctrine type. We can strip tel: on conversion, but we don't do that to make stuff more standarized.

kiler129 avatar Oct 01 '18 19:10 kiler129

Yeah, I've just done the same thing locally.

gnat42 avatar Oct 01 '18 19:10 gnat42

I have also discovered this issue. This is on a brand new setup, so BC is not an issue.

when you say to use "setPhone() to extract extension to a separate field." do you mean in the entity? Do you have a code example of the getter and setter methods you use for this?

webmasterMeyers avatar Oct 10 '19 19:10 webmasterMeyers