From: www.itworld.com

Setting up a Linux-based Website, Part 3: The power and the pitfalls of using PHP for Web programming

by Nicholas Petreley

April 12, 2001 —

 

I have a confession to make: I am an undisciplined programmer at heart. Unless there is some external motivation to do otherwise, I tend to jump in and start coding a project with no formal plans. This approach usually leads to code that is difficult to extend or maintain, because one only discovers the true requirements of a project by bumping into the limitations of what has already been coded. The result is a continual state of rewrites.

This makes me somewhat of a hypocrite, because I quickly get annoyed with others who do the same -- most recently with PHP-Nuke. I've been modifying PHP-Nuke 4.4.1a for use as the publishing system for VarLinux.org and Petreley.org, which is a site I'm doing in my off-hours. (See Resources for more information on the Websites mentioned in this article.) PHP-Nuke is a Weblog publishing system, written in PHP, with MySQL as the database back end.

To be fair, PHP-Nuke's programmers may not have deliberately taken a disorganized approach; they may have simply fallen into some common PHP traps. Although it is entirely possible to build a modular Website with PHP, the language tends to discourage modularity because PHP code integrates right into HTML.

That is why PHP is simultaneously irresistible and prone to disorganization. It is irresistible because with PHP, you can crank out MySQL data and turn it into a page of information more easily than with just about any other Web-programming system. It is prone to disorganization because the HTML opening formatting tags that you create inside a PHP function are often completed by other PHP functions. That means that every time you change the opening formatting tags, you have to find every occurrence where the closing tags must match. The format tags that get you into trouble most often are the table, row, and data tags. If you don't handle those tags properly, many of your page elements will be scattered into the wrong places.

One way to avoid this is to create a function for every combination of opening and closing tags. Then you have to maintain only those functions, not the formatting within other functions. In the current version of PHP-Nuke, you can see that the coders tried to implement this in some places, but it was probably too late to revamp the whole project without starting over. That is what they ultimately did, though -- PHP-Nuke 5.0 is on its way, and it is built almost from scratch.

LinuxWorld.com links

The worst news is that I don't know of any HTML syntax checkers that can process PHP pages. And I wouldn't expect to find any, because it would be extremely difficult for a checker to anticipate every combination of functions and code, and process every conditional statement to determine what tags get used when. If you know of any work being done on this, please pass on the info and I'll publish it here.

I encountered the aforementioned problems when I began to modify PHP-Nuke themes, and PHP-Nuke itself, for use with VarLinux.org. There are many sample themes for use with PHP-Nuke; the ones I chose to modify for use with VarLinux.org were fairly sloppy. Unfortunately, I checked my work using only the KDE Konqueror browser, Mozilla 0.8, and occasionally Opera for Linux. All of those browsers rendered my site beautifully, even though the theme code was riddled with errors. Only when Netscape users reported messy rendering did I began to look for those errors. I found dozens, scattered throughout the themes and the PHP-Nuke code itself. (Granted, I probably introduced many of the errors myself while modifying PHP-Nuke to meet my needs.)

Fortunately, the new release I mentioned will probably address many of the modularity issues. I recommend taking a good long look at the old and new versions of PHP-Nuke. Feel free to download my modified version from the VarLinux.org Website, if only to have a good laugh at my expense. I also plan to look at a very promising product called LXP. (See Resources for more information.) I recommend that you do the same. I'll get back to you after I've had the software in my hands for a while.

Another publishing system worth examining is eZ publish. (See Resources for more information.) I had trouble with this software and gave up on it, perhaps too quickly. It appears to be extremely feature-rich and powerful. I've also found it impossible to get started with CMF 1.0, the content management system for Zope. It looks very nice; I can't help but wonder what using it would be like. Two more systems to look at are Thatware and Squishdot for Zope.

Finally, I highly recommend studying many of the PHP-Nuke themes available on the PHP-Nuke Website. I'm not an HTML guru by any means. I can barely grok the concept of nested tables after messing with the themes for my site. But I learned an awful lot about how to use tables to create certain visual effects, simply by trying to reproduce the effects of the existing themes and correcting all the mistakes I made in the process.

Indeed, I'd say that working with PHP-Nuke, along with the available themes, is one of the best tutorials on PHP and HTML formatting I've ever seen.

Well, unless I encounter some new challenges for the VarLinux.org site, that about wraps up my experience with it for now. Please feel free to visit the site, add your comments and suggestions, and report any bugs you find.

Resources