Building Helpers in PHP 5 (
Page 1 of 4 )
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.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!
| | Discuss Building Helpers in PHP 5 | | | | | | | This series of articles introduces you in a friendly way to creating different... | | | | | | Helper is the most basic usecase for object and thus doesn't need the design... | | | | | | Good post, but rather unnecessary. I’m afraid you didn’t read the whole article, or... | | | | | | Hello, Alejandro!
I just think that helpers must be static classes. | | | | | | Hello,
Please read my below post or just go through the second part of this... | | | | | | I don't know what this article is attempting to show, but it is neither Helpers nor... | | | | | | That’s your opinion, which I do respect. But mine is that your concept about what a... | | | | | | this article is somewhat unproductive - you mess with instance of helper, not using... | | | | | | I do respect your opinion, but definitively you’re wrong. Here, I’m not promoting... | | | | | | Where can I find article telling how to call helper?
Do I need to use require_once... | | | | | | Thanks for commenting. If you’re going to put the helper in a separate file, then... | | | | | | I've been learning and using PHP since 2005 when I gave up on MSFT's .NET. I have... | | | | | | Hey SalP,
Thanks for the kind words on my PHP articles. I really appreciate them... | | | | | | >>> Post your comment now! | | | | | |
|
 |