-- Sancar Saran <[EMAIL PROTECTED]> wrote
(on Thursday, 24 April 2008, 03:03 PM +0300):
> On Thursday 24 April 2008 14:39:51 Matthew Weier O'Phinney wrote:
> > -- Greg Donald <[EMAIL PROTECTED]> wrote
> >
> > (on Wednesday, 23 April 2008, 04:04 PM -0500):
> > > What is gained by using Zend_Registry? Seems to me I could more
> > > easily use the existing PHP $GLOBALS or even $GLOBALS['registry'] if I
> > > wanted/needed a namespace.
> > >
> > >
> > > Zend_Registry::set('index', $value);
> > >
> > > versus
> > >
> > > $GLOBALS['index'] = $value;
> >
> > Globals are a really bad idea in almost every case, and they lead to
> > some really hairy problems with scoping, determining how and when a
> > variable is set, and much more. Do some googling for 'php globals
> > problems', and you'll start to get the idea. Try wrapping existing code
> > that relies on globals in an MVC framework some time, and you'll start
> > to see the issues quickly and noisily.
> >
> > A Registry is a design pattern that is used to solve the problems of
> > globals in a more maintainable and predictable way.
> >
> > That said, you're free to use $GLOBALS instead of Zend_Registry if you
> > still fail to see the point or simply prefer $GLOBALS.
>
> Hello There,
>
> I strongly against your arguments.
>
> Using globals with namespace does not create any problems. Searcing google
> "php globals problems" produces nothing.
>
> I strongly believe "using globals in php creates problems" is a MYTH. This
> myth creted by programmers who has strong c and c++ backgrounds.
To the contrary, I have no C or C++ background. But I've been bitten in
the ass by the use of $GLOBALS before, and I've blogged about it:
http://weierophinney.net/matthew/index.php?serendipity%5Baction%5D=search&serendipity%5BsearchTerm%5D=globals
It's much easier to think of things in the local scope than it is to
consider multiple scopes, and a registry helps to flatten the scope.
> Large and popular projects like phpAdodb and Typo3 (as far as I know) uses
> GLOBALS effecively and problem free.
I'm not saying that they can't be used problem free, but I am saying
that when you mix and match globals with OOP libraries, you can, and
will, run into problems, particularly when initializing globals within
a class method.
> I use GLOBALS for
> Language key pairs
> Static Config variables
> (Db, memcache, etc) resource pointers
>
> I was much faster and pratic than any oo way..
They are much faster, because you're not making any function calls, and
they will work as expected *if* you do the initializations in the global
scope. When you start doing the initializations inside method calls,
things get dicey.
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/