minor #15825 Fix potential access to undefined index (Seldaek)

This PR was merged into the 2.8 branch.

Discussion
----------

Fix potential access to undefined index

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Fixes @tobion's comment in https://github.com/symfony/symfony/pull/14563/files#r39705270

Commits
-------

de41002 Fix potential access to undefined index
This commit is contained in:
Fabien Potencier 2015-10-11 10:02:03 +02:00
commit 45b2382f46
1 changed files with 5 additions and 1 deletions

View File

@ -55,7 +55,11 @@ class EventDispatcher implements EventDispatcherInterface
public function getListeners($eventName = null, $withPriorities = false)
{
if (true === $withPriorities) {
return $eventName ? $this->listeners[$eventName] : array_filter($this->listeners);
if (null !== $eventName) {
return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
}
return array_filter($this->listeners);
}
if (null !== $eventName) {