Skip to content

Commit

Permalink
Improve FormBuilderIterator with removing accessing private propertie…
Browse files Browse the repository at this point in the history
…s over reflection

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 3be220d
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 3be220d

Please sign in to comment.