Skip to content

Commit

Permalink
minor #19765 [Validator] feat: add warning for number constraints wit…
Browse files Browse the repository at this point in the history
…h PHP 7.x (alexislefebvre)

This PR was merged into the 5.4 branch.

Discussion
----------

[Validator] feat: add warning for number constraints with PHP 7.x

Fixes symfony/symfony#45710

See:
- symfony/symfony#45710

Symfony 6.x requires PHP 8.x and it fixes this inconsistency, see symfony/symfony#45710 (comment)

So this patch should be removed when merging `5.4` in `6.0` (or `6.4`).

Commits
-------

7341079 feat: add warning for number constraints with PHP 7.x
  • Loading branch information
javiereguiluz committed Apr 9, 2024
2 parents 7f51be3 + 7341079 commit 0b170c8
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions reference/constraints/GreaterThan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Class :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThan`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanValidator`
========== ===================================================================

.. include:: /reference/constraints/_php7-string-and-number.rst.inc

Basic Usage
-----------

Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/GreaterThanOrEqual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Class :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqu
Validator :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqualValidator`
========== ===================================================================

.. include:: /reference/constraints/_php7-string-and-number.rst.inc

Basic Usage
-----------

Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/LessThan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Class :class:`Symfony\\Component\\Validator\\Constraints\\LessThan`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\LessThanValidator`
========== ===================================================================

.. include:: /reference/constraints/_php7-string-and-number.rst.inc

Basic Usage
-----------

Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/LessThanOrEqual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Class :class:`Symfony\\Component\\Validator\\Constraints\\LessThanOrEqual`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\LessThanOrEqualValidator`
========== ===================================================================

.. include:: /reference/constraints/_php7-string-and-number.rst.inc

Basic Usage
-----------

Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/Negative.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Class :class:`Symfony\\Component\\Validator\\Constraints\\Negative`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\LessThanValidator`
========== ===================================================================

.. include:: /reference/constraints/_php7-string-and-number.rst.inc

Basic Usage
-----------

Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/NegativeOrZero.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Class :class:`Symfony\\Component\\Validator\\Constraints\\NegativeOrZero`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\LessThanOrEqualValidator`
========== ===================================================================

.. include:: /reference/constraints/_php7-string-and-number.rst.inc

Basic Usage
-----------

Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/Positive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Class :class:`Symfony\\Component\\Validator\\Constraints\\Positive`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanValidator`
========== ===================================================================

.. include:: /reference/constraints/_php7-string-and-number.rst.inc

Basic Usage
-----------

Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/PositiveOrZero.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Class :class:`Symfony\\Component\\Validator\\Constraints\\PositiveOrZero`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqualValidator`
========== ===================================================================

.. include:: /reference/constraints/_php7-string-and-number.rst.inc

Basic Usage
-----------

Expand Down
6 changes: 6 additions & 0 deletions reference/constraints/_php7-string-and-number.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. caution::

When using PHP 7.x, if the value is a string (e.g. ``1234asd``), the validator
will not trigger an error. In this case, you must also use the
:doc:`Type constraint </reference/constraints/Type>` with
``numeric``, ``integer`, etc. to reject strings.

0 comments on commit 0b170c8

Please sign in to comment.