Home >Backend Development >PHP Tutorial >Class declaration and instantiation

Class declaration and instantiation

WBOY
WBOYOriginal
2016-07-29 08:57:511283browse

Declaration method

(modification keyword) class class name {

member attribute

member method

}

note

1 .Only one file is saved Class, the file name contains the class name. The advantage of naming it this way is to facilitate the automatic loading of future programs

2. The members in the class must belong to this class

3. There must be modified keywords before the member attributes, I don’t know If you want to add anything, use Var

to instantiate the object

$Object name = new Class name

Creating an object means allocating a space in the memory

External member access of the object

Access through objects

$object name->$property name=

$object name->$methodname()

Access to members in an object

is in an object In the internal method, to access other methods and member properties in the object method

Use the $this keyword to call the object of this method, which is equivalent to the first person "I"

$this cannot be accessed outside the class

The above introduces the declaration and instantiation of classes, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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