Closed palanisamy-emis closed 2 years ago
what is the issue ?
Hello,
Thank you for trying to report an issue. But as @maxhelias highlighted, you are not referring any issue related to the phone number bundle.
Please provide actual issue as well as the version you are using (you may just use a too old version and should upgrade).
Hello, I have the same deprecated message:
Yeah I. too. have the same deprecated message. It came from validator/Constraints/PhoneNumber.php. @Nek- @, @maxhelias
Which version of the bundle are you using?
v3.6.2 @OskarStark
You should not pass an array when declaring the constraint.
- new PhoneNumber(['defaultRegion' => 'GB']);
+ new PhoneNumber(defaultRegion: 'GB');
- #[AssertPhoneNumber(['defaultRegion' => 'GB']]
+ #[AssertPhoneNumber(defaultRegion: 'GB')]
- * @AssertPhoneNumber({"defaultRegion": "GB"}]
+ * @AssertPhoneNumber(defaultRegion="GB"]
I'm using the Assert like this everywhere in my code:
i'll keep checking what is causing the message
I'm using odolbeau/phone-number-bundle v3.6.2
The origin of this issue is here: https://github.com/doctrine/annotations/blob/1.13.x/docs/en/custom.rst#optional-constructors-with-named-parameters
We should add @NamedArgumentConstructor
annotation, but should we handle the situation, when the class NamedArgumentConstructor
is missing?
Thank you @okorneliuk for pointing that out!
So here it is. If you specifies the (optional) format
argument, you will have a deprecation issue. The way to avoid any problem is to follow directives in the documentation:
With annotations:
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;
// https://github.com/odolbeau/phone-number-bundle/blob/v3.4.2/README.md#validating-phone-numbers
/** @AssertPhoneNumber(defaultRegion="GB") */
private $phoneNumber;
With attributes:
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;
// https://github.com/odolbeau/phone-number-bundle#validating-phone-numbers
#[AssertPhoneNumber(defaultRegion: 'GB')]
private $phoneNumber;
In plain PHP:
new PhoneNumber(defaultRegion: 'GB');
That said, the annotation version have a little issue, connected to the annotation declaration missing option. This is why I suggest this PR: #119
The fix on the annotation has been merged. This issue can be closed :) .
I'm sorry to comment on a closed issue. I see that this was closed last July, and two new versions (3.8.0 in October and 3.9.0 in December) were released after that. Nonetheless, the issue is still present.
Just to be more clear, the following is the validation configuration I'm using:
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"
>
<class name="MyNamespace\MyClass">
<property name="phone">
<constraint name="Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber">
<option name="defaultRegion">IT</option>
</constraint>
</property>
</class>
</constraint-mapping>
I checked the README and, even if in a different format, this is the suggested way to use a default region. Unfortunately, this is still causing the deprecation warning to be present (probably the solution proposed in the linked PR was not enough)
Thank you for highlighting this @garak . I opened https://github.com/odolbeau/phone-number-bundle/pull/139 to fix it. Do you think it will fix your issue?
Thank you for highlighting this @garak . I opened #139 to fix it. Do you think it will fix your issue?
Yes, it does. Thank you for the prompt response.
Usage of the argument $format to specify options is deprecated and will be removed in 4.0. Use "$option" argument instead