Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 31f105e

Browse files
not use reflection to get value of FormType::$emptyData
1 parent 7d9556e commit 31f105e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

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

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

3439
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
3540
{
@@ -159,7 +164,7 @@ public function configureOptions(OptionsResolver $resolver)
159164
};
160165

161166
// Derive "empty_data" closure from "data_class" option
162-
if (self::$emptyData === null) {
167+
if (null === self::$emptyData) {
163168
self::$emptyData = function (Options $options) {
164169
$class = $options['data_class'];
165170

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)