API16

JRegistry/getInstance: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Returns a reference to a global JRegistry object, only creating it if it doesn't already exist. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[...
 
m clean up
Line 2: Line 2:
Returns a reference to a global JRegistry object, only creating it if it doesn't already exist.
Returns a reference to a global JRegistry object, only creating it if it doesn't already exist.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JRegistry/getInstance|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JRegistry/getInstance}}
 
{{subst:Description:JRegistry/getInstance}}


===Syntax===
===Syntax===
Line 52: Line 50:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JRegistry/getInstance|Edit See Also]]<nowiki>]</nowiki>
{{subst:SeeAlso:JRegistry/getInstance}}
</span>
{{SeeAlso:JRegistry/getInstance}}


===Examples===
===Examples===

Revision as of 14:19, 24 March 2017

Description

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


{{subst:Description:JRegistry/getInstance}}

Syntax

static getInstance($id, $namespace= '_default')
Parameter Name Default Value Description
$id An ID for the registry instance
$namespace '_default' The default namespace for the registry object [optional]

Returns

object The object.

Defined in

libraries/joomla/registry/registry.php

Importing

jimport( 'joomla.registry.registry' );

Source Body

public static function getInstance($id, $namespace = '_default')
{
        static $instances;

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

        if (empty ($instances[$id])) {
                $instances[$id] = new JRegistry($namespace);
        }

        return $instances[$id];
}


{{subst:SeeAlso:JRegistry/getInstance}}

Examples

<CodeExamplesForm />