Section three-Defining a class
When you declare a class, you need to list all the variables and all functions that the object should have-called properties and methods. The composition of a class is shown in 3.1.1. Note You can only declare variables or functions within curly braces ({}). 3.1.2 shows how to define three properties and two methods in a class.
3.1.1
Class Name extends another class
{
Access Variable Declaration
Access Function Declaration
}
3.1.2
Define a class that tracks users
Class User
{
Property
Public $name;
Private $password, $lastLogin;
Method
Public function __construct ($name, $password)
{
$this->name = $name;
$this->password = $password;
$this->lastlogin = time ();
$this->accesses++;
}
Gets the last access time
function Getlastlogin ()
{
Return (Date ("M D Y", $this->lastlogin));
}
}
Create an instance of an object
$user = New User ("Leon", "sdf123");
Gets the last access time
Print ($user->getlastlogin (). "
");
http://www.bkjia.com/PHPjc/445267.html www.bkjia.com true http://www.bkjia.com/PHPjc/445267.html techarticle section III-Defining a class when you declare a class, you need to list all the variables that the object should have and all of the functions are called properties and methods. The composition of a class is shown in 3.1.1. Note in the large enclosed ...