PHP Autoload

May 30, 2009 No comments yet

In large PHP applications you typically see a “classes” directory that only contains classes which are used throughout the application (database, session management, forms etc..). A problem quickly appears: Everytime you wanted to use one of the classes, you would be forced to include() it at the top of the page. __autoload() solves this by automatically including the definition file when a class is called.

Example

We have a simple application with the index.php file in the root directory and a directory called classes that contains numerous classes.
classes/time.class.php

class time
{
	function fn1()
	{
		echo 'hello world';
	}
}

The code below shows what we’d need to do if we didn’t have autoload. While that code doesn’t seem so bad, imagine writing includes on each of your 30-40 files. It would get messy and very hard to maintain. Another option would be to have a single file that all of your classes are included in, there include that one file in each of your functional scripts but you could expect a performance loss as every one of your classes would be included on the page – even if it wasn’t needed.

index.php

include('classes/time.class.php');

$time = new

Web Development Tools on Linux

May 2, 2009 No comments yet

While there are numerous posts and tutorials detailing web development tools for Windows and Mac operating systems scattered throughout the internet, there are very little for Linux. I’ll show and describe the tools I use to code PHP, Python, Javascript, HTML and CSS on a Linux platform (Ubuntu 8.10). None of these tools are distro specific.

Netbeans

Netbeans is a full featured IDE written in Java by Sun. Some people prefer Eclipse and Eclipse based IDEs (Aptana) but I find them slow and laggy on my system. The current Netbeans version in the Ubuntu repositories is 6.1, whlie this is good for Java and C++ developement, PHP support wasn’t included until 6.5.X. You can download the PHP package here – 26mb. Netbeans comes with standard project support, code completion, syntax highlighting and searching. What sets Netbeans apart from the rest is that it has on the fly PHP debugging (that works!). It also has version control support out of the box and in general it’s very quick.

screenshot_0011

Gedit

Gedit is the default text editor for GNOME, if you use GNOME, chances are it is already installed. If not you can find it by the package name gedit in…