php - Class with magic methods, global array, or..? -


i downloaded simple mvc, , converting how be.

i see in index.php entry point file, register object (class code below) instantiated , template , router object passed accessible globally in mvc architecture.

what difference using global array instead? isn't simpler? or there better way of handling this?

i'm looking better way of passing these objects.

i have read magic methods not because it's hard debug , re-factor. have read similar things global arrays.

class registry {     private $vars = array();      public function __set($index, $value) {         $this->vars[$index] = $value;     }      public function __get($index) {         return $this->vars[$index];     } } 

if question "what's registry class, better array?" then: class wrapper around array, it's useless. imo it's because thought using classes instead of arrays automatically makes code object oriented (which wrong). or maybe he/she wanted give array fancy name make purpose clearer (registry).

you can drop class , use array instead if want to, won't loose anything.

or if want better, can start learn dependency injection , di containers (which alternative pattern "registry" pattern == global array).


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -