PHP (3) object-oriented features-how to encode the singularity PHP5 began to support object-oriented programming. PHP's object-oriented programming method is not much different from other languages. next we will make a simple record of PHP's basic programming-oriented syntax.
I. object declaration
Declaration method:
Class Say {
Public function SayHello (){
Echo 'Hello World! ';
}
}
This completes the simplest object declaration.
Constructor:
Class Say {
Private $ _ lang;
Public function _ construct ($ lang ){
$ This-> _ lang = $ lang;
Echo 'the language is $ this-> _ lang ';
}
Public function SayHello (){
Echo 'Hello World! ';
}
}
This is how the constructor works.
II. objects used
Call other PHP file methods:
Require 'sayphp ';
However, when this method is called repeatedly, an error of repeated definitions is reported. Therefore, another method is generally used:
Require_once 'sayphp ';
In this way, no error will be reported for repeated calls.
Then a new object is created:
$ A = new Say ('China ');
Use member functions:
$ A-> SayHello ();