Skip to content

Commit dacae59

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: drop type-hints for properties where the Type constraint is used
2 parents a29413a + d7071c7 commit dacae59

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

reference/constraints/Type.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ Validator :class:`Symfony\\Component\\Validator\\Constraints\\TypeValidator`
1414
Basic Usage
1515
-----------
1616

17-
This will check if ``emailAddress`` is an instance of ``Symfony\Component\Mime\Address``,
17+
This constraint should be applied to untyped variables/properties. If a property
18+
or variable is typed and you pass a value of a different type, PHP will throw an
19+
exception before this constraint is checked.
20+
21+
The following example checks if ``emailAddress`` is an instance of ``Symfony\Component\Mime\Address``,
1822
``firstName`` is of type ``string`` (using :phpfunction:`is_string` PHP function),
1923
``age`` is an ``integer`` (using :phpfunction:`is_int` PHP function) and
2024
``accessCode`` contains either only letters or only digits (using
@@ -33,19 +37,19 @@ This will check if ``emailAddress`` is an instance of ``Symfony\Component\Mime\A
3337
class Author
3438
{
3539
#[Assert\Type(Address::class)]
36-
protected Address $emailAddress;
40+
protected $emailAddress;
3741
3842
#[Assert\Type('string')]
39-
protected string $firstName;
43+
protected $firstName;
4044
4145
#[Assert\Type(
4246
type: 'integer',
4347
message: 'The value {{ value }} is not a valid {{ type }}.',
4448
)]
45-
protected int $age;
49+
protected $age;
4650
4751
#[Assert\Type(type: ['alpha', 'digit'])]
48-
protected string $accessCode;
52+
protected $accessCode;
4953
}
5054
5155
.. code-block:: yaml

0 commit comments

Comments
 (0)