Home arrow PHP arrow Completing a Sample String Processor with Method Chaining

Completing a Sample String Processor with Method Chaining

In this third part of a 12-part series on method chaining, I complete the definition of the sample string processor class. This process will help reaffirm the concepts that you learned before regarding the definition and implementation of chainable methods in PHP 5.

  1. Completing a Sample String Processor with Method Chaining
  2. Review: the string processor class
  3. Replacing characters of a string with HTML entities
  4. Replacing and reversing characters of a literal
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
October 28, 2009

print this article



Method chaining is a simple, yet powerful, programming approach that permits you to write classes whose methods can be easily linked with each other, thus building a modular and highly-compact API. Logically, as with other methodologies, chainable methods are not a proprietary feature of a particular programming language, but rather an approach that can be used for developing both client and server-side web applications, and desktop programs as well.

Fortunately, PHP developers like you also can take advantage of the benefits of using method chaining when working with the object-oriented paradigm. In this series of articles you'll find numerous examples that not only will introduce you to the basics of this approach, but will show you how to use it in the context of real-world applications.

Naturally, if you already read the two preceding tutorials of the series, then at this stage you have a clearer idea of how to build chainable methods in PHP 5. In  those articles I developed a basic string processor class, which implemented some simple chainable methods for applying different filters to an incoming string.

In addition, it's fair to recall that this sample class defined a factory method (also chainable), which allowed you to create a singleton of the string processor without having to call its constructor directly.

However, it'd be pretty instructive to expand the existing functionality of the mentioned class by adding a few additional methods to it, which will also be  completely chainable. In this third chapter of the series I'm going to finish developing this string processor class by incorporating into it some chainable methods that will be tasked with replacing characters in an inputted string with their equivalent HTML entities, and with for reversing their value as well.

Now, it's time to continue creating more examples on using method chaining in PHP 5. Let's jump in!

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