[EventDispatcher] don't count empty listeners

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #11444
| License       | MIT
| Doc PR        | 

When event listeners for certain events are removed from the event
dispatcher, empty arrays are not being removed. Therefore, counting
on empty arrays leads to wrong results of the hasListeners() method.

Thanks to @mlindenb for discovering this an proposing a solution.
I moved the ``array_filter()`` call.