API15

JUser/getInstance

From Joomla! Documentation

< API15:JUser

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Returns a reference to the global User object, only creating it if it doesn't already exist.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

& getInstance($id=0)
Parameter Name Default Value Description
$id 0 $id The user to load - Can be an integer or string - If string, it is converted to ID automatically.

Returns[edit]

The User object. 

Defined in[edit]

libraries/joomla/user/user.php

Importing[edit]

jimport( 'joomla.user.user' );

Source Body[edit]

function &getInstance($id = 0)
{
        static $instances;

        if (!isset ($instances)) {
                $instances = array ();
        }

        // Find the user id
        if(!is_numeric($id))
        {
                jimport('joomla.user.helper');
                if (!$id = JUserHelper::getUserId($id)) {
                        JError::raiseWarning( 'SOME_ERROR_CODE', 'JUser::_load: User '.$id.' does not exist' );
                        $retval = false;
                        return $retval;
                }
        }

        if (empty($instances[$id])) {
                $user = new JUser($id);
                $instances[$id] = $user;
        }

        return $instances[$id];
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]