Home arrow PHP arrow Registry Classes in Action with Late Static Bindings in PHP 5.3

Registry Classes in Action with Late Static Bindings in PHP 5.3

In this second part of the series, I show you how useful late static bindings can be for dealing with a hierarchy of classes in static environments. In this case, the classes that compose that hierarchy are simple implementations of the registry design pattern, but this feature can be utilized in different situations and yield similar results.

TABLE OF CONTENTS:
  1. Registry Classes in Action with Late Static Bindings in PHP 5.3
  2. Review: definitions of previous registry classes
  3. The registry classes in action
  4. Including an autoloader class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
May 18, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The release of PHP 5.3.0 a few months ago put a big smile on the face of many developers. This major upgrade of the language has been packaged with some new and exciting features that allow you to build more robust and reliable applications, particularly when using the object-oriented paradigm. By far, the most relevant improvement in the language has been the support for native namespaces, which elegantly and maturely prevents clashes that might occur when naming classes. Itís fair to note, however, that the incorporation of anonymous functions, along with late static bindings, are useful enhancements that deserve special mention as well.

Even though theyíve been underrated from the very beginning by some programmers, the truth is that late static bindings (LSB) are a powerful feature that permits you to solve common problems that arise when working when hierarchies of classes in a static context, although itís also possible to use LSB at instance-level with the same ease.

Of course, explaining the theoretical facets of LSB isnít very useful. The best way to understand its actual functionality is by seeing an example. With that premise in mind, in the introductory part of this series I demonstrated how to use LSB to create a simple hierarchy of classes composed of a couple of registries. The first of these classes was an abstract registry, while the second was a refined implementation of its abstract parent, responsible for storing and fetching data from a private array.

Since the array-based registry inherited a Singleton static method from its abstract parent, LSB was used to return an instance of the calling class at runtime, which was impossible to achieve prior to PHP 5.3. While this sounds all well and good, I have to admit that at this point I've shown only the definitions of these sample classes, and not how to use them in a concrete case, which isnít very helpful from a didactic point of view.

Thus, in the lines to come Iím going to set up an example that will illustrate how work with this pair of registry classes, so you can see how powerful LSB actually is. So click on the link below and begin reading.



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: