Home
XHTML
CSS
PHP
MySQL
SEO
JavaScript
Computer Basics
Number Systems
LINUX


PHP Classes

PHP | Values | Operators | Functions | Arrays | Forms | Sessions-Cookies | Classes

A class is a group of objects with related properties and methods. Properties are variables local to the object. Methods are functions local to the object. An object is a template, which instances can be called for use of its properties. Objects are created with the same naming conventions as a variable.

The class command declares a new class, followed by the name of the class. The class definition is declared within  { }  side brackets. Properties are stored in variables. The var command declares a variable within the class. The new command calls an object, storing it in a new variable. The new variable becomes the instance of the object. The  ->  operator calls a property from the object...

<?php

class ClassName {
var $propertyName1="Northwest";
var $propertyName2="Southwest";}

$objectName=new ClassName();

echo "I live in the " . $objectName -> propertyName1 . "!";

?>

The output is...

I live in the Northwest!




The function command declares the method.  $this  is a unique variable for referencing the current object...

<?php

class ClassName {
var $propertyName1="Northwest";
var $propertyName2="Southwest";
function functionName() {
echo "I travel to the " . $this -> propertyName2 . "!";}}

$objectName=new ClassName();
$objectName -> functionName();

?>

The output is...

I travel to the Southwest!




SEO Vancouver, Washington
SEO Portland, Oregon
Website Design Vancouver, Washington