Skip to content

Commit 938176f

Browse files
authored
Merge pull request #2339 from dafriend/session_returns_null_with_zero_value
Fix Session::get('key') returns null when value is (int) 0
2 parents 59a314a + 556961f commit 938176f

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

system/Session/Session.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ protected function configure()
305305
);
306306

307307
//if (empty($this->sessionExpiration))
308-
if (!isset($this->sessionExpiration))
308+
if (! isset($this->sessionExpiration))
309309
{
310310
$this->sessionExpiration = (int) ini_get('session.gc_maxlifetime');
311311
}
@@ -496,7 +496,7 @@ public function set($data, $value = null)
496496
*/
497497
public function get(string $key = null)
498498
{
499-
if (! empty($key) && $value = dot_array_search($key, $_SESSION))
499+
if (! empty($key) && ! is_null($value = dot_array_search($key, $_SESSION)))
500500
{
501501
return $value;
502502
}
@@ -634,7 +634,7 @@ public function __get(string $key)
634634
*
635635
* @param string $key Identifier of the session property to remove.
636636
*
637-
* @return bool
637+
* @return boolean
638638
*/
639639
public function __isset(string $key): bool
640640
{

tests/system/Session/SessionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ public function testGetReturnsNullWhenNotFound()
129129
$this->assertNull($session->get('foo'));
130130
}
131131

132+
public function testGetReturnsItemValueisZero()
133+
{
134+
$_SESSION = [];
135+
136+
$session = $this->getInstance();
137+
$session->start();
138+
139+
$session->set('foo', (int) 0);
140+
141+
$this->assertSame((int) 0, $session->get('foo'));
142+
}
143+
132144
public function testGetReturnsAllWithNoKeys()
133145
{
134146
$_SESSION = [

0 commit comments

Comments
 (0)