diff --git a/src/Symfony/Component/Stopwatch/Stopwatch.php b/src/Symfony/Component/Stopwatch/Stopwatch.php index 50ac6574fd436..8961507fa07db 100644 --- a/src/Symfony/Component/Stopwatch/Stopwatch.php +++ b/src/Symfony/Component/Stopwatch/Stopwatch.php @@ -140,7 +140,7 @@ public function getEvent(string $name): StopwatchEvent */ public function getSectionEvents(string $id): array { - return $this->sections[$id]->getEvents() ?? []; + return isset($this->sections[$id]) ? $this->sections[$id]->getEvents() : []; } /** diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php index f1e2270018447..f9b532efe1fe4 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php @@ -187,4 +187,9 @@ public function testReset() $this->assertEquals(new Stopwatch(), $stopwatch); } + + public function testShouldReturnEmptyArrayWhenSectionMissing() + { + $this->assertSame([], (new Stopwatch())->getSectionEvents('missing')); + } }