Skip to content

Commit 4139a0c

Browse files
committed
feature #42387 [Form] Deprecate calling FormErrorIterator::children() if the current element is not iterable (W0rma)
This PR was merged into the 5.4 branch. Discussion ---------- [Form] Deprecate calling FormErrorIterator::children() if the current element is not iterable | Q | A | ------------- | --- | Branch? | 5.4 for features | Bug fix? | yes | New feature? | no | Deprecations? | yes | Tickets | symfony/symfony#42301 (comment) | License | MIT | Doc PR | Commits ------- d8e74fc8df * Deprecated calling `FormErrorIterator::children()` if the current element is not iterable
2 parents 90220d7 + 2f24e21 commit 4139a0c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.4
55
---
66

7+
* Deprecate calling `FormErrorIterator::children()` if the current element is not iterable.
78
* Allow to pass `TranslatableMessage` objects to the `help` option
89

910
5.3

FormErrorIterator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Form\Exception\BadMethodCallException;
1515
use Symfony\Component\Form\Exception\InvalidArgumentException;
16+
use Symfony\Component\Form\Exception\LogicException;
1617
use Symfony\Component\Form\Exception\OutOfBoundsException;
1718
use Symfony\Component\Validator\ConstraintViolation;
1819

@@ -213,13 +214,16 @@ public function hasChildren()
213214
}
214215

215216
/**
216-
* Alias of {@link current()}.
217-
*
218217
* @return self
219218
*/
220219
#[\ReturnTypeWillChange]
221220
public function getChildren()
222221
{
222+
if (!$this->hasChildren()) {
223+
trigger_deprecation('symfony/form', '5.4', 'Calling "%s()" if the current element is not iterable is deprecated, call "%s" to get the current element.', __METHOD__, self::class.'::current()');
224+
// throw new LogicException(sprintf('The current element is not iterable. Use "%s" to get the current element.', self::class.'::current()'));
225+
}
226+
223227
return current($this->errors);
224228
}
225229

0 commit comments

Comments
 (0)