Skip to content

Commit

Permalink
Improve FormBuilderIterator: Remove reflection
Browse files Browse the repository at this point in the history
The property 'children' is not always accessible or even available because several implementations of other FormBuilders do not have this property.
Accessing private properties is never a good idea. Only rely on the given FormBuilderInterface.
  • Loading branch information
Mike Meier committed Apr 11, 2016
1 parent 61d8a4b commit 6060b93
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions Util/FormBuilderIterator.php
Expand Up @@ -65,12 +65,7 @@ public function __construct(FormBuilderInterface $formBuilder, $prefix = false)
*/
private static function getKeys(FormBuilderInterface $formBuilder)
{
if (!self::$reflection) {
self::$reflection = new \ReflectionProperty(get_class($formBuilder), 'children');
self::$reflection->setAccessible(true);
}

return array_keys(self::$reflection->getValue($formBuilder));
return array_keys($formBuilder->all());
}

/**
Expand Down

0 comments on commit 6060b93

Please sign in to comment.