Home arrow PHP arrow Building Helpers in PHP 5

Building Helpers in PHP 5

Tired of repetitive coding for tasks such as generating web site breadcrumbs? PHP 5 provides a number of interesting ways to reuse your code so you can let the boring stuff take care of itself. This eight-part series will show you how to create helpers to take care of repetitive tasks and free up your precious coding time for the real challenges.

  1. Building Helpers in PHP 5
  2. Building a helper in PHP 5
  3. Extending the functionality of the text helper class
  4. The text helper class in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
July 20, 2009

print this article



When it comes to speeding up the development of web applications, experienced PHP programmers tend to be rather lazy, and I'm not using that adjective with a negative connotation. Popular concepts like "don't reinvent the wheel" and DRY (short for "don't repeat yourself") help developers avoid creating PHP programs from scratch, while maintaining a high level of control over how their logic is implemented.

Naturally, as you may have guessed, the most direct and simplest application of these concepts is code reuse. This concept can be applied through a variety of custom and third-party libraries, packaged in the form of classes or functions, or a combination of both.

Undoubtedly, the ultimate implementation of code reuse is a full-featured framework. Such frameworks provide developers with a set of well-trusted classes, modules, plug-ins and helpers that permit them to build complex web-based programs very quickly and without suffering premature hair loss.

But, wait a minute! If you reread the previous sentence, you'll notice that I subtly introduced the term "helpers." What are they? Well, if you still haven't coded one on your own, helpers are usually small blocks of reusable code that help programmers to perform certain repetitive tasks.

A helper usually can be structured as one single class or as a set of functions, and the things it does generally aren't as complex as those done by a full-blown library. Common tasks that must be performed over and over again with different projects, such as building portions of a URL, generating web site breadcrumbs and formatting chunks of text, are typical functions of helpers, to cite just a few illustrative examples.

Despite its seeming simplicity, building helpers can be a pretty challenging process, particularly for beginners whom are just starting to implement the object-oriented paradigm in PHP 5. So, in this series of articles, I'm going to introduce you as gently as possible to creating different types of helpers, which hopefully will make you understand the basis of this process and encourage you to create your own.

Now, it's time to get rid of the boring theory and start learning how to build helpers with PHP 5. Let's begin right away!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


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