public static function getUser($id = null)
{
$instance = self::getSession()->get('user');
if (is_null($id))
{
if (!($instance instanceof JUser))
{
$instance = JUser::getInstance();
}
}
elseif ($instance->id != $id)
{
$instance = JUser::getInstance($id);
}
return $instance;
}
When I write a unit test case for a function, which has the code JFactory::getUser(); inside, then I need to set user in session. Otherwise session does not contain anything, and return NULL on first line of function. If $instance is null then it gets an error for "Accessing undefined property on on non-object" ($instance->id ).
There should be a check before using "elseif ($instance->id != $id)"
Run this script from command line (in order to better represent the issue being addressed, a command line environment is preferred as web requests do not seem to hit this issue)
Pre-patch, you should get a Notice: Trying to get property of non-object in libraries/joomla/factory.php on line 246 message
test works as described