Class
Sum up a few words
:
①
Classes are abstract and represent a class of things
Ii
object is specific and is a concrete instance of a class
③
Class is a template for an object
,
An object is an individual instance of a class
Construction method
?
Construction method
No return value
,
It is automatically called
2.
In
PHP 5
In a class can have both
Two forms of construction method
__construct ()
And
Class name
() ,
When two exist at the same time, the first call
__construct (),
Please use after everyone
__construct ()
?
1. $this
It's the address of the object that can be understood.
2.
Which object is used to
$this,
is which object address
3. $this
Cannot be used outside the class
.
Can only be used within a class
Considerations for construction methods
(1)
Once a constructor has been customized, the default
The constructor is overwritten.
,
When you create an object, you will use a custom
constructor function
.
(2)
A class can have only one constructor
. (
Cannot reload
)
of the construction method
8
Point description
:
① constructor method name and class name are the same
(PHP4
Version
), PHP5
Version of the construction method
The name can be the same as the class name, or it can be
__construct () (PS:
Two
_)
PHP Object-oriented summary