EllisLab/CodeIgniter — Issue #712: unset_userdata () fatal bug
Author: Llbe
Created: 2011-11-25 16:32:48+00:00
State: open

Hi

unset_userdata () in stable version 2.0.3 and version 2.1.0 looks like this:

function unset_userdata($newdata = array())
{
if (is_string($newdata))
$newdata = array($newdata => '');

if (count($newdata) > 0)
{
foreach ($newdata as $key => $val)
{
unset($this->userdata[$key]);
}
}
..

Now this will fail when doing unset_userdata (8096) for example, obviously because of is_string (). Thus this is a fatal bug. Another oddity is the use of count (), which is unnecessary since a foreach () on an empty array () is perfectly valid.

This should be changed to:

function unset_userdata($newdata = array())
{
if (! is_array ($newdata))
$newdata = array($newdata => '');

foreach ($newdata as $key => $val)
{
unset($this->userdata[$key]);
}
..

/ Llbe