PHP - Advantages Of Closures
What are the advantages of closures? When do we need to implement closures? Can you please explain?
Thanks in advanced. Similar TutorialsHiya, I'm still hesitant on starting my project, as I am unsure whether or not to code everything using classes or not. Whilst searching the net for inspiration, I came across this script on Code Canyon. Does this script have to be coded in a class, or can the same results be achieved by simply using functions. What would be the main advantage(s) for coding such a script using classes? This is still something I have difficulty getting my head around. I would appreciate any body's thoughts on this topic. Thanks, FishSword Trying to improve my script-architecture, I got curious about other ways to pass application-data around aside from using the$GLOBALS array. The only other way I really found was to use an object called a "Registry". I just ended up being confused regarding when which method is better than the other, let alone how to even use a registry-object in my scripts. So my questions a - When is it better to use a registry object in place of global data? - how would you use a registry? - how would a registry object get passed around, through other objects and functions? Heres the registry I found... class registry { var $_cache_stack = array(); function __construct(){ $this->_cache_stack = array(array()); } function set($key, &$item){ $this->_cache_stack[0][$key] = &$item; } function &get($key){ return $this->_cache_stack[0][$key]; } function isEntry($key){ return ($this->getEntry($key) !== null); } function &instance(){ static $registry = false; if (!$registry) $registry = new Registry(); return $registry; } function save(){ array_unshift($this->_cache_stack, array()); if (!count($this->_cache_stack)) exit('Registry lost!'); } function restore(){ array_shift($this->_cache_stack); } } |