When accessing the member variables or methods in the PHP class, if the referenced variables or methods are declared as const (defining constants) or static (declaring static), the operator must be used:: otherwise, if the referenced variable or method is not declared as cons... when accessing the member variables or methods in the PHP class, if the referenced variables or methods are declared as const (defining constants) or static (declaring static), the operator must be used:: if the referenced variable or method is not declared as const or static, you must use the operator->.
In addition, if you access const or static variables or methods from the inside of the class, you must use self-referenced. Otherwise, if the internal access from the class is not a const or static variable or method, then you must use the self-referenced $ this.
The $ this instance code is as follows:
Content = $ content;} function _ destruct () {}// defines the destructor function printContent () {// defines the print function echo $ this-> content .'
';}}$ Test = new test_this ('welcome to Beijing! '); // Instantiate the object $ test-> printContent (); // Beijing welcomes you!?>
: The usage example code is as follows:
Name = $ name ;}} class test_son extends test_parent {// the derived class inherits test_parent public $ gender; // defines the gender public $ age; // define the age function _ construct ($ gender, $ age) {// Constructor parent ::__ construct ('nostop') of the inherited class '); // Use parent to call the constructor of the parent class to instantiate the parent class $ this-> gender = $ gender; $ this-> age = $ age ;} function _ destruct () {} function print_info () {echo $ this-> name. 'is '. $ this-> gender. ', this year '. $ this-> age. 'year '.'
';}}$ Nostop = new test_son ('female', '22'); // instantiate the test_son object $ nostop-> print_info (); // execution of the output function nostop is a female, 23 years old?>
Use the self: $ name format. note the statement format of the const attribute. const PI = 3.14 instead of const $ PI = 3.14.
The instance code is as follows:
Note that if the class method is static, the Accessed attribute must also be static.
Use $ this-> value = 'class _ A'; in the form of $ this-> value = 'class _ A' when the internal method of the class is not declared as const or static.
Article address:
Reprint at will ^ please include the address of this article!