View Single Post
  #1 (permalink)  
Old 04-16-2008, 05:58 AM
tangfucius tangfucius is offline
Junior Member
 
Join Date: Apr 2008
Posts: 3
Default Zend_Registry useless?

According to this article: PHPit - Totally PHP Using globals in PHP
Global variables have the following problems:

1. Reusing parts of the script is impossible
If a certain function relies on global variables, it becomes almost impossible to use that function in a different context. Another problem is that you can’t take that function, and use it in another script.

2. Solving bugs is much harder
Tracking a global variable is much harder than a non-global variable. A global variable could be declared in some obscure include file, which could take hours to find, although a good text editor / IDE could help with this.

3. Understanding the code in a year will be much more difficult
Globals make it difficult to see where a variable is coming from and what it does. You might know about every global during development, but after a year or so you’ll probably have forgotten at least half of them, and then you’ll be kicking yourself for using so many globals.

Then the author proposes Registry as the eventual solution to global variables… But I really don’t see how the Registry pattern really solves the above 3 problems. You still can’t reuse part of the code if the objects aren’t created and stored in the Registry first, just like the global variables have to be created first. You still will run into bugs if you don’t take care of your Registry well. You still will find the code difficult to understand if you don’t remember where you are processing your Registry. None of the problems caused by global variables is really solved here, Registry Pattern is fundamentally identical to global variables, and it really seems the “improvement” is more so the mental perception than actuality.

I'm posting it here so people who are knowledgeable can perhaps shine some light on solid reasons that Registry Pattern is actually as good as people say it is?
Reply With Quote