Home arrow PHP arrow Creating a Static Web Form Helper with Restrictive Constructors

Creating a Static Web Form Helper with Restrictive Constructors

Welcome to the final installment of a series that shows you how to use restrictive constructors in PHP 5. With a decent variety of code samples, this series recreates for you a few common scenarios where the implementation of both protected and private constructors can greatly improve the behavior of different classes in the context of a given application.

TABLE OF CONTENTS:
  1. Creating a Static Web Form Helper with Restrictive Constructors
  2. Review: using a private constructor in a Singleton class
  3. Building a static web form helper class with a private constructor
  4. Using the previous Form helper class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
March 23, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

And now that you've been properly introduced to the subject of this series, itís time to briefly recapitulate the topics that were covered in the last tutorial. In that part of the series I built a basic MySQL abstraction class, which used a private constructor in conjunction with a static method called ďgetInstance()Ē to turn the class into a Singleton.

The functionality of this abstraction class was actually quite limited; it only was capable of running queries, fetching rows in data sets, and performing a few more basic tasks. Still, it came in handy for demonstrating how a private constructor can be of great help in implementing the Singleton design pattern in a strict fashion.

However, as I mentioned a moment ago, there are different situations where a restrictive constructor can be employed in a truly useful manner; one of them happens to be when building purely static classes. In most cases (not all of them, naturally), presentation helpers are good candidates for turning into static classes. In the lines to come Iím going to code one for you that will declare a private constructor.

In this particular case, the helper that Iím going to build will take care of rendering different elements of an HTML form in a pretty straightforward way, but itíll be conceived to be used only out of the object context.

It sounds like a pretty educational experience, right? Thus, to learn the full details regarding the construction of this purely static web form helper, jump ahead and start reading the following lines!



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