Skip to content

Commit 4dbe623

Browse files
committed
bug symfony#9338 [DoctrineBridge] Added type check to prevent calling clear() on arrays (bschussek)
This PR was merged into the 2.2 branch. Discussion ---------- [DoctrineBridge] Added type check to prevent calling clear() on arrays | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 4ff59d7 [DoctrineBridge] Added type check to prevent calling clear() on arrays
2 parents 1b97ad4 + 4ff59d7 commit 4dbe623

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form\EventListener;
1313

14+
use Doctrine\Common\Collections\Collection;
1415
use Symfony\Component\Form\FormEvents;
1516
use Symfony\Component\Form\FormEvent;
1617
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -40,7 +41,7 @@ public function onBind(FormEvent $event)
4041

4142
// If all items were removed, call clear which has a higher
4243
// performance on persistent collections
43-
if ($collection && count($data) === 0) {
44+
if ($collection instanceof Collection && count($data) === 0) {
4445
$collection->clear();
4546
}
4647
}

0 commit comments

Comments
 (0)