Home arrow PHP arrow Factoring (X)HTML Objects with Late Static Bindings in PHP 5.3

Factoring (X)HTML Objects with Late Static Bindings in PHP 5.3

In this fifth part of a six-part series on late static bindings, I define some sample classes which are responsible for creating some block-level (X)HTML objects, such as simple divs and paragraphs. Once we get these classes up and running, we'll be ready to test the factories created in the previous part and see if they’re actually as functional as they look.

TABLE OF CONTENTS:
  1. Factoring (X)HTML Objects with Late Static Bindings in PHP 5.3
  2. Review: using Late Static Binding in the object scope
  3. Defining generic (X)HTML objects
  4. Building some block-level (X)HTML objects
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
May 25, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As you’ll possibly know, PHP 5.3 includes, among a few other useful things, a new feature called Late Static Bindings (LSB). It comes in handy for resolving at runtime from which class a given static method has been called. Even though this major release of the language also offers a solid support for native namespaces and closures, the sole inclusion of LSB is worth the upgrade. This characteristic allows you to create flexible hierarchies of classes that will be used mostly in a static context.

Logically, if you’ve been a loyal follower of this article series, you're already familiar with the benefits provided by LSB. In previous tutorials I demonstrated how to use LSB to build a hierarchy of Singleton registry classes without having to override their static “getInstance()” method, which was impossible to achieve prior to PHP 5.3.

I left off the last installment of the series explaining how to take advantage of the functionality offered by LSB in the object scope by defining a couple of basic factory classes. The first of these classes was an abstract factory, while the second one was a refined implementation of its abstract parent, tasked with creating some block-level (X)HTML objects. However, what made these classes truly interesting (especially the concrete one) was the ability to spawn the above mentioned (X)HTML objects either statically via a static method called “create(),” or dynamically via the pertinent constructor. And guess what? Yes, this functionality was implemented thanks to the use of LSB!

It’s valid to notice, though, that at this stage I only showed the definitions of the factories, but not of the ones that originate the block-level (X)HTML objects. To address this issue, in this penultimate part of the series I’m going to start creating those classes, so you can see how they will be consumed later on by the factories in question.

Let's get started. There are lots of code samples waiting for us!



 
 
>>> 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: