Home > Backend Development > PHP Tutorial > Differences between php this, self and parent

Differences between php this, self and parent

巴扎黑
Release: 2016-11-21 13:31:40
Original
1434 people have browsed it

1、this是指向当前对象的指针
如:同class里面的其他函数可以用 this->函数名 调用。
2、self是指向当前类的指针
一般self使用来指向类中的静态变量,还要注意使用self来调用静态变量必须使用:: (域运算符号)
如:self::$firstCount;      //使用self来调用静态变量
3、parent是指向父类的指针
一般我们使用parent来调用父类的构造函数
如:parent::__construct( "PBPHome");    //使用parent调用了父类的构造函数
Copy after login


source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template