Classes and objects are powerful OOP concepts - and PHP4 supportsthem too. This article explains some basic OO entities (including classes,constructors and extensibility) with examples of a table builder and aguestbook.
In case you need to access functions or modify variables within the class definition itself, PHP offers the $this keyword, which is used to refer to "this" class. For example, if you were to add Henry Ford's edict of "any colour, so long as it's black" to the definition above, you'd end up with something like this:
class Automobile
{
// this is where the properties are defined
var $colour;
var $shape;
...
// this is where the functions are defined
function start()
(
// code goes here
)
function turnColourBlack()
{
$this->colour = "Black";
}
...
}
In this case, the $this prefix indicates that the variable to
be modified is included within the current class definition - or, in English, "change the value of the variable $colour within this class to Black". The $this prefix thus provides a convenient way to access variables and functions which are "local" to the class.