mardi 6 septembre 2016

Registry pattern - the difference with reference and without

Following this guide, but it is always difficult for me to understand references in PHP. What is the purpose of using reference in the params below?

public function register($name, &$object)
{
    $this->registries[$name] =& $object;
}
public function &getRegistry($name)
{
    return $this->registries[$name];
}

Without the references:

public function register($name, $object)
{
    $this->registries[$name] = $object;
}

public function getRegistry($name)
{
    return $this->registries[$name];
}

It works fine too without the the references, so what is the advantages having them?

Aucun commentaire:

Enregistrer un commentaire