"Extending PHP" is easier said than done. PHP has evolved to a
full-fledged tool consisting of a few megabytes of source code,
and to hack a system like this quite a few things have to be
learned and considered. When structuring this chapter, we finally
decided on the "learn by doing" approach. This is not the most
scientific and professional approach, but the method that's the
most fun and gives the best end results. In the following
sections, you'll learn quickly how to get the most basic
extensions to work almost instantly. After that, you'll learn
about Zend's advanced API functionality. The alternative would
have been to try to impart the functionality, design, tips,
tricks, etc. as a whole, all at once, thus giving a complete look
at the big picture before doing anything practical. Although this
is the "better" method, as no dirty hacks have to be made, it can
be very frustrating as well as energy- and time-consuming, which
is why we've decided on the direct approach.
Note that even though this chapter tries to impart as much
knowledge as possible about the inner workings of PHP, it's
impossible to really give a complete guide to extending PHP that
works 100% of the time in all cases. PHP is such a huge and
complex package that its inner workings can only be understood if
you make yourself familiar with it by practicing, so we encourage
you to work with the source.
The name Zend refers to the language engine,
PHP's core. The term PHP refers to the
complete system as it appears from the outside. This might sound
a bit confusing at first, but it's not that complicated (see
Kuva 25-1). To implement a Web script interpreter, you need
three parts:
The interpreter part analyzes the input
code, translates it, and executes it.
The functionality part implements the
functionality of the language (its functions, etc.).
The interface part talks to the Web
server, etc.
Zend takes part 1 completely and a bit of part 2; PHP takes parts
2 and 3. Together they form the complete PHP package. Zend itself
really forms only the language core, implementing PHP at its very
basics with some predefined functions. PHP contains all the
modules that actually create the language's outstanding
capabilities.
The following sections discuss where PHP can be extended and how
it's done.