From: www.itworld.com
March 23, 2001 —
Should you learn PHP? Probably so, if:
Humble beginnings
Rasmus Lerdorf wrote a rudimentary version of the PHP scripting language in late 1994 as an aid to managing his personal homepage. (Originally the name PHP stood for Personal Home Page Tools; it eventually became a recursive abbreviation for PHP: Hypertext Preprocessor). Several languages -- Perl, Python, and even exotica like Scheme and Icon -- can do what PHP does: compute HTML pages on the server side of a Web application. PHP is unique, though, in that it is specifically designed to simplify that one task. You might reasonably expect, then, that PHP does it best. That certainly seems to be the belief of the few hundred thousand developers worldwide who are now enjoying the fourth major PHP release.
Take a moment to understand clearly what server-side computation means for a Web application. A minimal Webpage might have source that looks like this:
<HTML>
<HEAD>
<TITLE>
Home page for John Smith
</TITLE>
</HEAD>
<BODY>
This is John Smith's first home page.
</BODY>
</HTML>
Suppose now, that John wants to replace
This is John Smith's first homepage.
with
This is John Smith's first homepage.
John has completed XXXX Webpages.
One way to accomplish this would be for John to simply edit in "one" or "two" or n in place of XXXX. This works well enough for text that changes infrequently.
If John's a busy fellow, though, he'll likely want to "automate" his page -- that is, have the computer itself figure out parts of its content. At that point, his page will become dynamic.
If dozens of languages can generate dynamic Webpages, how do you choose among them? My first criterion is the social one: if your friends and colleagues are comfortable with PHP, then you should try it. While languages differ profoundly in a technical sense, most of them have roughly the same capabilities for introductory and intermediate-level Web work. Let computing specialists argue the details of syntactic theory; if you just want to get work done, use the same language that those around you use.
Often, that language is PHP. PHP is probably available for the Web server you use. It's easy for beginners to pick up. It has a helpful community of programmers worldwide. A great wealth of tutorial material is available at no cost on the Web. And PHP handles the most common Web chores quietly and efficiently. PHP is a nice, safe way to improve your Webpages.
A first example
Here's one example: with PHP, the fragment above might become
This is John Smith's first home page.
<?php
$count = `ls -l *.html | wc -l`;
echo("John has completed $count Web pages.");
?>
This is typical for PHP source: it mixes plain HTML source (This is John Smith's first homepage.) with small <?php ... ?> pieces that figure a result that varies with time, user, data entered into a Web form, or other context. The PHP segment is often no more than a couple of lines long, as in this case.
Code that computes the number of John's *.html sources might look a bit foreign if you're not accustomed to command-line operations. Don't let this scare you, though. PHP builds in scores of functions to handle common Web operations, including access to a variety of databases, FTP and HTTP operations, XML parsing, date-and-time formatting, and even Cybercash transactions. A typical PHP source simply steps through several common function calls, "glued" together with a variable assignment or two.
A natural development path for PHP programmers is to start out as HTML coders. If you're already a confident Web designer, you can begin gently with a line or two of PHP decoration in your existing pages. That seems to provide a more comfortable transition for many experienced Web professionals than alternatives like Perl or server-side JavaScript.
PHP makes Web work easy
Part of the difficulty with languages like Perl is that they began life outside the Web. Having been designed for more general purposes, they are imperfectly streamlined for Web work. Even if you already know popular Web languages like Perl, Python, or Tcl, you might enjoy learning PHP. If you specialize in Web work, you're likely to find that you're more productive with PHP.
Of course, some other languages do focus narrowly on Web applications. What makes PHP exceptional is its "openness" and portability. Like Perl, recent releases of PHP are available under both the GPL and an artistic-style license. Competing Web tools like Microsoft's Application Server Pages (ASP) are proprietary products available only for favored operating systems, often to the exclusion of Linux. PHP is cross-platform.
The corporate side of PHP
Let's review: you're a good candidate for PHP if you want to compose more elaborate Web pages or applications, if you work with others experienced in PHP, if you find languages like Perl too involved or "heavy," or if you like the friendly helpfulness that is common among PHPers. These scenarios have all been present almost from the time of PHP's origin. But is there anything new to tell about the language?
Absolutely. One of the great achievements of the PHP community since its first release has been its facility for transacting data access from many database management systems (DBMSs), including Oracle, MySQL, and InterBase. These "bindings" are efficient, up-to-date, and available for nearly all platforms that PHP supports. The quality of DBMS bindings makes PHP a favorite of developers who are responsible for corporate sites that track customers, merchandise, purchases, credit information, and other data.
This increasingly commercial orientation expresses itself in the IT marketplace. Zend Technologies Ltd., a for-profit company that focuses exclusively on PHP and allied technologies, contributed a great deal to the PHP4 release, which is many times faster than PHP3 on several common operations. Zend offers support for PHP, along with proprietary high-end products like development tools and "enterprise solutions" based on PHP. Zend had a Grand Opening for the "Zend Store" on January 23, 2001.
PHP extends its reach
Until PHP4, PHP served almost exclusively as a language for server-side Web programming. Part of the re-engineering involved in PHP4, though, makes it practical to package the PHP language in new forms, the most popular being PHP as a command-line "shell." Scott Hathaway, lead programmer for Infotrain Solutions, uses "batch" PHP in a "mission-critical" service to access Crystal Reports through a COM object coded in Visual Basic. While programmers have traditionally used Perl, JavaScript, or other languages for this sort of administrative or text-processing work, now PHP can fill the same role. A few pioneers used command-line PHP3. PHP4, though, simplifies its management.
At the heart of PHP4 is a licensed product called the Zend Engine. Zend chief technical officer and PHP evangelist Jim Jagielski explains that it
is sort of like the kernel of PHP4. Since the Zend Engine is the parsing core, it means that you can use the Zend Engine in other projects that need that kind of capability. This is in addition to the fact that you can use PHP4 as a command-line shell.
Later in 2001 this flexibility may extend even within the MySQL database server, with PHP scripts used as stored procedures within MySQL databases.
There's one more PHP innovation that you should know about. Suppose you work with an IT department that's coded a big, complicated Java method that uses an array of demographic variables to predict car-repair prospects. You'd like to make a bit of that intelligence available through a Web application you're developing. When you ask how you can get at it, though, your colleagues just mutter about "JVM incompatibility," "JSP," and other esoterica that sound like code words for "obstacle."
Don't despair! PHP comes to your rescue. PHP knows how to use Java classes others have written. In fact, specialists can offer a good argument that PHP is a better language than Java itself (that is, better than Java Server Pages) for developers who simply want to use existing Java classes in their Web applications.
Here's why: IBM senior programmer Sam Ruby has given PHP4 the capability to create Java objects and invoke Java methods. This facility seems to be particularly popular among Web programmers making sophisticated use of XML.
Conclusion
If you're a Web worker learning your first "real" computing language, PHP is a great place to start: you'll find it useful immediately, and your fellow PHP programmers are a cheerful and helpful bunch. If you already know basic PHP, make a point of learning how its new command-line, database, and Java capabilities can multiply your capabilities and productivity.
LinuxWorld.com