Home arrow PHP arrow PHP 5 Helpers: Calling Methods Out of Object Scope

PHP 5 Helpers: Calling Methods Out of Object Scope

Theoretically defining the role of helper classes in PHP 5 (and other popular server-side scripting languages) is a pretty approachable process. As their name suggests, helper classes provide developers with a set of logically-grouped methods that allow them to easily perform certain repetitive tasks that are common to different web applications. This is the second part of an eight-part article series that shows you how to build a variety of useful helper classes and expand on their functionality.

TABLE OF CONTENTS:
  1. PHP 5 Helpers: Calling Methods Out of Object Scope
  2. Review: building a text helper class
  3. Working with static methods
  4. The new text helper class in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
July 27, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Typical examples of helper classes are those that dynamically build portions of a URL and validate incoming data, or that apply specific text-formatting filters to a supplied string before doing something useful with it, such as inserting it into a database table. Feel free to add your own to the list.

While everything looks good in theory when it comes to defining what a helper class is, things can get more complex when putting this definition into practice. This is especially true for inexperienced PHP programmers just starting to use the object-oriented paradigm for building web-based programs.

So, if you need to expand your existing skills as a PHP developer and wish to learn how to build helper classes with PHP 5 by means of a true hands-on approach, then begin reading this series of articles right now!

In the first part of this series, I offered a gentle introduction to creating a text helper class. This class was tasked with applying some basic filters to an inputted string. If you've already read that article, then itís quite probable that you have a clear idea of how to build this kind of class in a relatively easy manner.

The methods of the class that I just mentioned were declared implicitly dynamic, even though itís perfectly possible to call them statically, and the PHP engine wonít raise any errors about this process. However, it would be much better to declare these methods explicitly static, thus taking advantage of the functionality offered by the text helper class without having to spawn an instance of it.

Therefore, in this second part of the series Iím going to use a decent variety of code samples to explain how to improve the use of the text helper class developed before by turning its regular methods into static ones.

Want to see how this will be accomplished in a few basic steps? Then go ahead and start reading right away!



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