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 3023dea commit c6a8a80
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions Util/FormBuilderIterator.php
Original file line number Diff line number Diff line change
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 c6a8a80

Please sign in to comment.