Skip to content

Commit ed68472

Browse files
not use reflection to get value of FormType::$emptyData
1 parent cb1ee76 commit ed68472

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@
2929
class FormType extends BaseType
3030
{
3131
private $dataMapper;
32-
private static $emptyData = null;
32+
33+
/**
34+
* @internal
35+
*
36+
* @deprecated Don't use this property. It will be removed in symfony/form 6.0
37+
*/
38+
public static $emptyData = null;
3339

3440
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
3541
{
@@ -159,7 +165,7 @@ public function configureOptions(OptionsResolver $resolver)
159165
};
160166

161167
// Derive "empty_data" closure from "data_class" option
162-
if (self::$emptyData === null) {
168+
if (null === self::$emptyData) {
163169
self::$emptyData = function (Options $options) {
164170
$class = $options['data_class'];
165171

src/Symfony/Component/Form/Extension/Core/Type/TextType.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2727
// See https://github.com/symfony/symfony/issues/5906#issuecomment-203189375
2828
if ('' === $options['empty_data']) {
2929
$builder->addViewTransformer($this);
30-
} elseif ($options['empty_data'] instanceof \Closure) {
31-
$emptyData = new \ReflectionProperty(FormType::class, 'emptyData');
32-
$emptyData->setAccessible(true);
33-
// Closure in "empty_data" option is the default value from FormType::configureOptions()
34-
if ($emptyData->getValue($builder->getForm()) === $options['empty_data']) {
35-
trigger_deprecation('symfony/form', '5.4', 'The default value of "empty_data" option in "%s" will be changed to empty string. Declare "NULL" as value for "empty_data" if you still want use "NULL" as data.', __CLASS__);
36-
}
30+
} elseif (FormType::$emptyData === $options['empty_data']) {
31+
// "empty_data" option is the default value from FormType::configureOptions()
32+
trigger_deprecation('symfony/form', '5.4', 'The default value of "empty_data" option in "%s" will be changed to empty string. Declare "NULL" as value for "empty_data" if you still want use "NULL" as data.', __CLASS__);
3733
}
3834
}
3935

0 commit comments

Comments
 (0)