O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6.3. Defining a Class

When you declare a class, you are really making a template for the creation of objects. You list all the variables the object should have and all the functions it will need. These are called properties and methods respectively. Figure 6.1 displays the form of a class declaration. Note that inside the curly braces you can declare only variables or functions. Listing 6.1 shows the definition of a class with three properties and two methods.

Figure 6.1. Defining a class.
						class Name extends Another Class
{
    Access Variable Declaration

    Access Function Declaration
}
					
Listing 6.1. Using a class
 <?php //define class for tracking users class User { //properties public $name; private $password, $lastLogin; //methods public function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required