From 131b5febe261079bfaa488055d85ff6eb63e62f1 Mon Sep 17 00:00:00 2001 From: Oleh Korneliuk Date: Tue, 18 Nov 2025 10:41:05 +0300 Subject: [PATCH 1/2] Use named arguments when guessing the type PHP 8 allows named arguments. It is more convenient way to use default values. --- forms.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/forms.rst b/forms.rst index bea93edb25d..b028c4a66b2 100644 --- a/forms.rst +++ b/forms.rst @@ -850,8 +850,7 @@ In the above example, Symfony can guess from the validation rules that the ``task`` field is a normal ``TextType`` field and the ``dueDate`` field is a ``DateType`` field. -To enable Symfony's "guessing mechanism", omit the second argument to the ``add()`` method, or -pass ``null`` to it:: +To enable Symfony's "guessing mechanism", omit the second argument to the ``add()`` method:: // src/Form/Type/TaskType.php namespace App\Form\Type; @@ -869,8 +868,8 @@ pass ``null`` to it:: $builder // if you don't define field options, you can omit the second argument ->add('task') - // if you define field options, pass NULL as second argument - ->add('dueDate', null, ['required' => false]) + // if you define field options, use named argument + ->add('dueDate', options: ['required' => false]) ->add('save', SubmitType::class) ; } @@ -902,7 +901,7 @@ the following options will be guessed too: If you'd like to change one of the guessed values, override it in the options field array:: - ->add('task', null, ['attr' => ['maxlength' => 4]]) + ->add('task', options: ['attr' => ['maxlength' => 4]]) .. seealso:: From 3a64f66aaf3954f7be9ba4bdc7912234b4ae9189 Mon Sep 17 00:00:00 2001 From: Oleh Korneliuk Date: Tue, 18 Nov 2025 11:05:29 +0300 Subject: [PATCH 2/2] Fixed code block --- forms.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forms.rst b/forms.rst index b028c4a66b2..69382865f7e 100644 --- a/forms.rst +++ b/forms.rst @@ -901,7 +901,7 @@ the following options will be guessed too: If you'd like to change one of the guessed values, override it in the options field array:: - ->add('task', options: ['attr' => ['maxlength' => 4]]) + $builder->add('task', options: ['attr' => ['maxlength' => 4]]) .. seealso::