To echo Benjamin, any scenario where static classes are called within another 
class open the door to problems with testing, portability and subclassing. It's 
for this reason it's always a good idea to minimise their use and at a minimum 
isolate the usage in central locations. Avoiding them is the most ideal 
situation.

The better solution is dependency injection, and one facet of this is removing 
explicit references to Registry/global items from source code. This is a 
feature the ZF has yet to include but Bradley Holt has ressurected the idea in 
the form of Zend_Container ( 
http://framework.zend.com/wiki/display/ZFPROP/Zend_Container+-+Bradley+Holt ) 
and I really really hope it, or an evolution of it (Zend_Application plugin?), 
makes it into the library. The last time something like this was proposed it 
was bogged down by ever expanding requirements and complexity - simpler is 
better.

Paddy

 Pádraic Brady

http://blog.astrumfutura.com
http://www.survivethedeepend.com
OpenID Europe Foundation Irish Representative





________________________________
From: Benjamin Eberlei <[email protected]>
To: [email protected]
Sent: Saturday, January 10, 2009 7:03:47 PM
Subject: Re: [fw-general] Is Cal Evan's Globals.php a recommended approach


the registry is global too and it has no type checking, which makes a
global
class that has setter and getter for specific types winner over a
general registry in my opinion.

static classes that contain objects and are used inside dynamic objects are
always
an obstacle to testing, singletons more than registries but the problem
does not
disappear. a registry is nothing different than a "global
$arrayWithObjects;" inside a function,
just object oriented.

The recommended approach (that is independend of Zend or whatnot) should
always be explicit
dependency injection.

greetings,
Benjamin

On Fri, 9 Jan 2009 23:31:38 -0500, Matthew Weier O'Phinney
<[email protected]> wrote:
> -- swilhelm <[email protected]
> wrote
> (on Friday, 09 January 2009, 12:26 PM -0800):
>>
>> I have been Reading Cal Evan's Guide to Zend Framework Programming.
>>
>> In it he describes a Globals.php file for creating a single class to
>> encapsulate access to global resources like the database connection,
> cache
>> connection, config, etc.
>>
>> This seems useful, particularly if you use it in conjunction with his
>> Controller_Request_Cli class for exposing some of your Zend-based
>> application via command line or cron jobs.
>>
>> I was wondering if this is the recommended approach to exposing global
>> resources or is there a Zend Framework "approved" method?
> 
> I've had some back and forth with Cal on his Globals class. :)
> 
> I personally feel that this is primarily the realm of a registry or
> dependency injection; a class of static methods is typically difficult
> to test against, and makes it more difficult to determine what the
> actual dependencies are for classes that pull from it.
> 
> Zend_Application may very well make such a Globals class obsolete, as it
> will make it easier to handle your dependencies and push them either
> into the registry or directly into the objects that need them.
> 
> --
> Matthew Weier O'Phinney
> Software Architect       | [email protected]
> Zend Framework           | http://framework.zend.com/

Reply via email to