PHP
  Home arrow PHP arrow Using Static Methods to Validate Data with Helpers in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Using Static Methods to Validate Data with Helpers in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2009-09-08


    Table of Contents:
  • Using Static Methods to Validate Data with Helpers in PHP 5
  • Review: checking incoming data with class methods
  • Declaring the class's methods to be static
  • Examples: validating input data with static methods

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Using Static Methods to Validate Data with Helpers in PHP 5
    ( Page 1 of 4 )

    Welcome to the conclusion of an eight-part series on building helpers in PHP 5. It's been a long journey, modifying our helper class to make it do what we want it to. Finally, in this last part, we'll put the finishing touches on our validation class so that it functions properly, without the need to spawn helper objects.

    For many PHP developers taking the first steps in the fascinating terrain of object-based programming, building helper classes is a mysterious process. That's easy to understand, considering the thin line of differentiation that sometimes exists between helpers and full-featured libraries.  

    Despite this initial intimidating feeling, the truth is that creating helper classes is very often much easier to accomplish than one might think. In most cases the process doesn't differ too much from developing a regular PHP class.

    However, it's also fair to say that generally methods of a helper class should be declared static, to avoid an eventual instantiation of the class itself. This makes sense, because in a typical situation it's not necessary to spawn helper objects at all. Instead, the functionality of a helper class is exploited through direct calls to its methods, but always out of the object scope.

    Of course, this is only a brief piece of theory behind building helper classes with PHP, which must be properly backed up with some practical examples that demonstrate this process. And that has been the goal of this series of articles, including the previous one, where I discussed how to use a basic helper class to validate different types of data. The data validated in that article ranged from integer and float numbers, to IP and email addresses as well.

    In addition, as you'll possibly recall, this sample helper had a serious drawback that contradicts the theoretical concepts deployed above. What was wrong with it? The methods of the helper were always called in the object scope, implying that there was a previous instantiation of the class. In this particular case, this process is completely unnecessary, aside from encouraging a bad programming habit.

    Therefore, in this last tutorial of the series I'm going to improve the source code of this validation helper class by declaring all of its implemented methods static. After doing that, I'm going to set up some examples that will show how to validate incoming data via these static methods.

    So, are you ready to tackle the final chapter of this hopefully educational journey on building helper classes in PHP 5? Then, start reading right now!



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

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek