Skip to content

Commit 6756f28

Browse files
committed
[Session] Fixed Backward Compatibility issue with getFlashes()
1 parent b7189fd commit 6756f28

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Symfony/Component/HttpFoundation/Session/Session.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ public function getFlashes()
256256
$return = array();
257257
if ($all) {
258258
foreach ($all as $name => $array) {
259-
$return[$name] = reset($array);
259+
if (is_numeric(key($array))) {
260+
$return[$name] = reset($array);
261+
} else {
262+
$return[$name] = $array;
263+
}
260264
}
261265
}
262266

src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ public function testGetSetFlashes()
183183
$this->assertEquals(array('notice' => 'foo'), $this->session->getFlashes());
184184
}
185185

186+
public function testGetFlashesWithArray()
187+
{
188+
$array = array('notice' => 'hello', 'error' => 'none');
189+
$this->assertEquals(array(), $this->session->getFlashes());
190+
$this->session->setFlash('foo', $array);
191+
$this->assertEquals(array('foo' => $array), $this->session->getFlashes());
192+
$this->assertEquals(array(), $this->session->getFlashes());
193+
194+
$array = array('hello', 'foo');
195+
$this->assertEquals(array(), $this->session->getFlashes());
196+
$this->session->setFlash('foo', $array);
197+
$this->assertEquals(array('foo' => 'hello'), $this->session->getFlashes());
198+
$this->assertEquals(array(), $this->session->getFlashes());
199+
}
200+
186201
public function testGetSetFlash()
187202
{
188203
$this->assertNull($this->session->getFlash('notice'));

0 commit comments

Comments
 (0)