Chapter 17: Finite State Machine and Custom Configuration Files


Most people would argue that PHP is a modern language, designed for modern applications. As are almost all modern Web development languages, it is regarded as being high level. It concerns itself more with rapid application development instead of allowing its programmers to fiddle with the underlying system directly for the sake of optimizing performance.

Indeed, languages that are particularly high level, such as PHP, further widen the gap now firmly established between programming in the traditional, computer science college-textbook sense of the word, and application development (using the language as simply a tool designed to solve a problem).

For example, it was not so long ago that games programmers were locked in a battle to determine who could produce the fastest assembly-language putpixel routine, to draw a single pixel on the screen. Nowadays, however, few games programmers concern themselves with such low-level matters, preferring instead to make use of Microsoft's DirectX library, which pretty much has it cracked. In much the same way, PHP takes the burden of developing low-level, highly tuned, optimized routines away from the programmer and exposes only useful functionality instead "tell me what you want me to do, not how you want me to do it.''

However, some of the more traditional programming techniques also have a role to play in PHP. We're not suggesting or recommending trying to get PHP to execute register-level CPU instructions, of course, but there is one more elderly concept worth resurrecting the Finite State Machine.

In this chapter, you'll meet the Finite State Machine in some detail, including learning what it does, how it does it, and how it can prove to be a useful solution to a variety of the more difficult and awkward challenges you might face in your own projects. After learning the basics of the FSM model, you'll meet a PEAR class that enables you to quickly and easily implement a basic FSM in PHP. As a proof of concept, you'll meet a simple programming puzzle solved using the FSM PEAR class and then dissect it piece by piece. In the process, you'll discover why that puzzle lends itself so well to implementation using an FSM, and how you might easily identify similar opportunities yourself. In the second half of this chapter, you'll look at the concept of user-modifiable configuration files, which provide an excellent example of an off-the-shelf Finite State Machine implementation. You'll see why they're important, what the role they play in your applications, and how best to go about implementing them in PHP.

Professional PHP5 (Programmer to Programmer Series)
Professional PHP5 (Programmer to Programmer Series)
Year: 2003
Pages: 182
BUY ON AMAZON © 2008-2017.
If you may any questions please contact us: