News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Fernando Bassani's Blog:
Avoiding the usage of global variables
July 30, 2007 @ 15:04:00

Fernando Bassani has posted an alternative to using globals in your scripts - creating "global objects" with the help of the Registry design pattern.

For a long time, the "programming good practices" tell us to avoid globals. In fact, this is a point of a large criticism in languages such as PHP. A nice solution to our global's "needs" is the Registry design pattern. With it, we can have a repository with the data that has to be accessible, removing them from the global scope.

Included in the post is all the code you'll need to get it to work. It uses a Singleton to grab the latest object and allows you to store values and define namespaces to keep data separate.

0 comments voice your opinion now!
registry designpattern singleton registry designpattern singleton


blog comments powered by Disqus

Similar Posts

DevShed: Working with Strings and the Composite Pattern in PHP 5

PHP-Tip-a-Day: PHP Tutorial: King Floyd and the Seventeen Princes - A Tale of the Observer Pattern

SitePoint PHP Blog: Repository Design Pattern Demystified

DevShed: Building a Data Validation System with the Prototype Pattern with PHP 5

PHPImpact Blog: Static Factories vs Public Constructors


Community Events

Don't see your event here?
Let us know!


php7 laravel part2 framework interview symfony project testing language application community opinion composer podcast list introduction api yii2 example series

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework