mercredi 14 août 2019

What are the advantages/disadvantages of accessing Registry through __get() & __set()?

In the context of MVC, I've come across various examples and implementations that access Registry in other classes via __set() & __get().

What are the implications of this? Does this lead to any unexpected behaviour? Is it a good practice?

class Controller { protected $registry;

public function __construct(Registry $registry) {
    $this->registry = $registry;
}

public function __get($key) {
    return $registry->$key;
}

public function __set($key, $value) {
    $registry->$key = $value;
}

}

Aucun commentaire:

Enregistrer un commentaire