PHPit - Totally PHP

January 03th, 2006   
Issue 7   

 Weekly PHP news, articles, tips and tricks! Newsletters Archives | Advertising | Contact Us  

In This Issue...

Introduction: Welcome 2006

Welcome to the first issue of the year 2006. I was actually supposed to send out an issue of the Digest last week, but hey, I was enjoying Christmas and New Year’s Eve, so I decided to postpone for a week. I’m sure ya’ll don’t mind.

What have I got in store for you this year? A lot, and I’m really excited to get started again. Last year was actually the launch of the Digest, and it’s really picking up steam. The same goes for PHPit, and it’s rapidly becoming one of the most popular PHP websites. This year I’ll be working extremely hard to make PHPit and the Digest even more popular.

One of the things I want to do is introduce other authors to the Digest. If you’re interested in taking over a section, or writing a new section, let me know at dennis@phpit.net. I’ve also got a few other things in the pipeline, but I’ll unveil those at another time.

In this issue I take a look at the phpMyChat script in the ‘Script of the Week’ section, and do a thorough review. Read more about it below.

In the Editor’s Perspective I talk about Unit Testing, and why you should or should not use it yourself. Unit testing has actually become quite popular in the last year, and there are definitely some advantages to unit testing. More in the Editor’s Perspective below.

Finally, the rest of this issue has the regular sections: an excerpt of the latest article on PHPit and the latest PHP articles around the ‘net.

Happy Reading!

Dennis Pallett
dennis@phpit.net

Editor’s Perspective: Unit Testing

In the past few months something called Unit Testing has been getting a lot of attention in the PHP community, but it isn’t a new concept. Java programmers have been unit testing for years now, but recently it has become popular in PHP, especially as more unit testing packages have been released. But what exactly is unit testing?

According to Google, “a unit test is a method of testing the correctness of a particular module of source code”. Basically, instead of manually testing your script by hand, you automatically run a few scripts that test every module of your script. Have a look at the following tutorial for a basic example: http://www.lastcraft.com/first_test_tutorial.php

There are several advantages to unit testing. First of all, you don’t have to manually test every aspect of your script. All you have to do is run the unit tests, and all the testing is done automatically. Another added benefit is the thoroughness of unit testing. If you test things manually it’s very easy to miss things, and certain bugs will most likely slip past you. With unit testing on the other hand nothing is missed, because everything is automatic. Granted, certain bugs can still be missed by your unit tests (especially bugs that only occur under certain circumstances), but it is a lot more methodical than doing it manually.

With those advantages also come a very big disadvantage, and that’s the fact that you actually have to write the unit tests, which can often take more time than the script itself. For every module and function of your script you have to write a unit test, and sometimes you even have to write multiple tests for the same function. This can lead to writing a lot of code, which takes a lot of time.

Another disadvantage of unit testing is that it requires your script to be very modular, which usually means a lot of design patterns and OOP. If your script hardly uses any OOP at all, you’ll probably find that unit testing isn’t really possibly.

For me, the disadvantages outweigh the advantages. Although I’d love to automatic testing, it just doesn’t work for me. I want to spend all my time on the script itself (and the things around it, docs, website, etc), and not writing hundreds of tests.

And most of my scripts aren’t really heavy on the OOP, so unit testing is hardly ever a possibility anyway. I might do it, if I used a lot of OOP, but until then, I won’t be unit testing.

I’d like to hear your opinion on this. There have been many debates on this the previous months, and opinions are still divided. Do you think Unit Testing has any merit? If so, do you actually do it yourself or not?

E-mail any feedback or comments to dennis@phpit.net

The Latest PHP Articles From Around The 'Net

Despite the fact that it was Christmas and New Year's Eve the past three weeks, there are still a lot of new articles. Let's start off with the new articles from DevShed. The first one, "An Image is Worth a Thousand Words in PHP" describes a fun little project that will help you sharpen your image manipulation skills. The article will show you all kinds of different image manipulation techniques. The second part, "An Image is Worth a Thousand Words in PHP Continued", has also been published already, and continues with what you learnt in part 1.

Next up we have "Dynamic Watermarking with PHP", which shows you how to dynamically watermark images with PHP and the GD library. Another article which shows you how to create dynamic images is "Dynamic Images", and it will show you how to create a dynamic signature image with people's IP address. A very short tutorial, but still useful nonetheless.

DevShed has also published two new PHP5 specific articles, called "User-defined Interfaces in PHP 5: Introduction to Core Concepts" and "User-defined Interfaces in PHP 5: Turning MySQL Classes into Interface Implementers". Both articles demonstrate the use of interfaces in PHP 5, which is something new, and does not exist in PHP 4. If you're wondering what they are, then these articles are a must-read.

Let's move over to a different website now. Informit has published a new article called "How To Create an RSS Aggregator with PHP and AJAX". A very informative article, with code samples, showing you how to create your own RSS aggregator using PHP and Ajax. The Symfony project has also posted an interesting article, called "symfony advent calendar day twenty-one: Search engine", showing you how to create a search engine in PHP with the Symfony framework.

Finally, PHPit has also published two new articles. In "Building an advertising system with PHP, Part 3", which is the third and final part of the advertising system series, you will be shown how to create some really neat charts from the advertising statistics. The component that is used to do this (PHP/SWF Charts) is a really neat library, and even if you're not interested in the article, I definitely recommend having a look at the charts.

PHPit has also published "Creating a chat script with PHP and Ajax, Part 1" in which you will learn how to create a live chat script with PHP and Ajax. Have a look at the demo of this article, as it's really neat.

To view a complete list of all the latest PHP articles, have a look at Webdev-Articles

Excerpt: Creating a chat script with PHP and Ajax, Part 1

In this multi-part tutorial series I will show you how to create your own chat script with PHP and Ajax. You've probably heard of Ajax before, and what it exactly is, but in case you haven't, read the following two tutorials to learn more about Ajax: "Mastering Ajax, Part 1: Introduction to Ajax" and "Getting started with Ajax".

Another JavaScript library we'll be using is the Prototype library, which includes many useful JavaScript functions and comes with inbuilt Ajax support. If you want to know more about this library, have a look at the following tutorial: "Using prototype.js v1.3.1".

In this first part of the series I will show you how to create a really basic chat script, and nothing more. In the next parts we'll be adding more features, eventually creating a really robust and powerful chat script.

Click here to read the rest of this article »

Script of the Week: phpMyChat

This time I take a look at phpMyChat, which is exactly what the name says: a chat script written in PHP. I've never heard of phpMyChat before, and I've never actually seen it been used anyway, but I took a quick look through the demo online, and it looked pretty neat, so I decided to download a copy of my own and give it a good test run. When I went to download it though, I made a rather shocking discovery: there hasn't been any update since 2001. But since the demo was pretty good, I decided to download it anyway.

After downloading the script, I was in for another "interesting" discovery: the script has actually been written in PHP 3, and each file had a .php3 extension. I had to configure my server to run those files as PHP, because they weren't recognized at first.

When I had PHP3 working, I pointed my browser to the setup.php3 file, and amazingly enough it worked. Installing the script itself was fairly easy in the beginning, and I was actually impressed, especially for a 4 year old script, but the end was somewhat difficult, and the instructions were a bit vague. After manually editing a few scripts, I managed to get everything working, but I don't think any one without PHP knowledge would've been able to get it up and running.

The script itself is actually quite stable and in working order, although the code looks extremely bloated and horrible but the end result looks good. I got no PHP errors at all, and the chat seemed to work fine. I was happily chatting away with myself.

The admin control panel is very simple, and lacked many features I was hoping to see. It only has three things: "registered users", where you can edit/delete users, "banished users" where you can ban and unban users and "clean rooms" where you can delete rooms. This is actually quite disappointing, and really shows that this script is nowhere near ready (that's probably why it's version 0.14.5). On the upside though, the chat itself (which is viewed by regular users) looks fairly polished.

Final verdict? It's an okay chat script, and I was surprised it actually works, but it's nothing I'd ever use on a production site. Thankfully, I've actually started on a chat script myself which is 10x better and advanced, so there's no need to use this script (more about this in a later issue of the Digest). If you're looking for a good PHP chat script right now, have a look at phpOpenChat which has been last released on March 17 2005. I will do a review on phpOpenChat soon as well, to compare it against phpMyChat.

Homepage: http://phpmychat.sourceforge.net
Price: FREE

Closing Words

That’s it again for this issue, and I hope you’ve enjoyed it. If you wish to comment on anything, or if you have any suggestions, please feel free to e-mail me at dennis@phpit.net

The next issue of the Digest will arrive somewhere on or around January 17, again filled with great content!

Until then, enjoy this issue, and visit PHPit for more articles, and join the excellent PHPit Forums to talk PHP.

Latest PHP Books


Pro PHP Security (Pro) - by Chris Snyder and Michael Southwell; Paperback
Buy new: $29.69


Beginning PHP, Apache, MySQL Web Development - by Michael K. Glass, Yann Le Scouarnec, et al; Paperback
Buy new: $26.39


PHP Functions Essential Reference (Essential Reference) - by Zak Greant, Graeme Merrall, et al; Paperback
Buy new: $29.38


PHP in a Nutshell (In a Nutshell) - by Paul Hudson; Paperback
Buy new: $19.77


Subscription Information
You are subscribed to the PHPit Digest through [subscriber_email]. If you no longer wish to receive the Digest, you can unsubscribe by clicking here.
Unsubscribe?   Copyright © 2005 The Pallett Group. All Rights Reserved.