Home >Backend Development >PHP Tutorial >Section 3 - Define a class - Classes and Objects in PHP5 [3]_PHP Tutorial

Section 3 - Define a class - Classes and Objects in PHP5 [3]_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-20 11:03:441012browse


Section 3 - Defining a Class
When you declare a class, you need to list all the variables and all the functions that the object should have - called properties and methods. 3.1.1 shows a class Composition. Note that 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
{
// Attributes
Public $ name;
PRIVATE $ Password, $ LastLogin;
// Method
Public Function __Construt ORD )
{
$this->name = $name;
$this->password = $password;
$this->lastLogin = time();
$this ->accesses++;
                                                                                                                                                                                                                                                                                          . ; > Print($user->getLastLogin() ."
");





http://www.bkjia.com/PHPjc/445267.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/445267.html

TechArticle

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn