When accessing member variables or methods in a PHP class, if the referenced variable or method is declared as const (defining constant) or static (declaring static), then you must use the operator::, otherwise if it is referenced The variable or method is not declared as const or static, then the operator -> must be used.
In addition, if you access a const or static variable or method from within the class, you must use self-reference. On the contrary, if you access a non-const or static variable or method from within the class, you must use self-reference. $this.
$this instance
The code is as follows | Copy code | ||||||||||||||||||||
private $content; //Define variables Function __construct($content){ //Define constructor $this->content= $content; } Function __destruct(){}//Define destructor Function printContent(){//Define printing function echo $this->content.' '; } } $test=new test_this('Welcome to Beijing!'); //Instantiated object $test->printContent();//Welcome to Beijing! ::Usage
Public $value; }source:php.cn
Previous article:What is a php file? How to open a php file_PHP tutorial
Next article:PHP determines whether a variable constant exists_PHP tutorial
Statement of this Website
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
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|