Skip to content

Commit

Permalink
when $_SESSION is null
Browse files Browse the repository at this point in the history
newest version.

CRITICAL - 2019-12-10 19:17:06 --> Argument 2 passed to dot_array_search() must be of the type array, null given, called in /home/zdamy/site/system/Session/Session.php on line 500
#0 /home/zdamy/site/system/Session/Session.php(500): dot_array_search('ausItem', NULL)
codeigniter4#1 /home/zdamy/site/system/Common.php(347): CodeIgniter\Session\Session->get('ausItem')
codeigniter4#2 /home/zdamy/site/app/Models/AdminUserModel.php(87): session('ausItem')



BTW/ I am not sure if that method should not look like:

```
public function get(string $key = null)
	{
		if (! empty($key))
		{
                        if(! is_null($value = dot_array_search($key, $_SESSION??[])))
                        {
                             return $value;
                         }
                         return null;
		}
		elseif (empty($_SESSION))
		{
			return [];
		}

		$userdata = [];
		$_exclude = array_merge(
			['__ci_vars'], $this->getFlashKeys(), $this->getTempKeys()
		);

		$keys = array_keys($_SESSION);
		foreach ($keys as $key)
		{
			if (! in_array($key, $_exclude, true))
			{
				$userdata[$key] = $_SESSION[$key];
			}
		}

		return $userdata;
	}
```
  • Loading branch information
nowackipawel authored Dec 10, 2019
1 parent dbf36b8 commit 8758dbe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion system/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public function set($data, $value = null)
*/
public function get(string $key = null)
{
if (! empty($key) && ! is_null($value = dot_array_search($key, $_SESSION)))
if (! empty($key) && ! is_null($value = dot_array_search($key, $_SESSION??[])))
{
return $value;
}
Expand Down

0 comments on commit 8758dbe

Please sign in to comment.