From 556961ff0d76b2301e4e10ea53edc1d19576bdbc Mon Sep 17 00:00:00 2001 From: dafriend Date: Wed, 16 Oct 2019 16:36:22 -0500 Subject: [PATCH] Fix Session::get('key') returns null when value is (int) 0 Issue #2334 --- system/Session/Session.php | 6 +++--- tests/system/Session/SessionTest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/system/Session/Session.php b/system/Session/Session.php index 80c87ea48549..3328804a5efb 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -305,7 +305,7 @@ protected function configure() ); //if (empty($this->sessionExpiration)) - if (!isset($this->sessionExpiration)) + if (! isset($this->sessionExpiration)) { $this->sessionExpiration = (int) ini_get('session.gc_maxlifetime'); } @@ -496,7 +496,7 @@ public function set($data, $value = null) */ public function get(string $key = null) { - if (! empty($key) && $value = dot_array_search($key, $_SESSION)) + if (! empty($key) && ! is_null($value = dot_array_search($key, $_SESSION))) { return $value; } @@ -634,7 +634,7 @@ public function __get(string $key) * * @param string $key Identifier of the session property to remove. * - * @return bool + * @return boolean */ public function __isset(string $key): bool { diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index c90729a25e5d..19f6c2404f56 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -129,6 +129,18 @@ public function testGetReturnsNullWhenNotFound() $this->assertNull($session->get('foo')); } + public function testGetReturnsItemValueisZero() + { + $_SESSION = []; + + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', (int) 0); + + $this->assertSame((int) 0, $session->get('foo')); + } + public function testGetReturnsAllWithNoKeys() { $_SESSION = [