Home  >  Article  >  Backend Development  >  Detailed explanation of php self and $this_PHP Tutorial

Detailed explanation of php self and $this_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:08:15986browse

Let’s talk about parent and self first:

Copy code The code is as follows:

/*
* Created by YinYiNiao
*/
class A{
function __construct(){
echo "Construction method of base class A
";
}
}
class B extends A{
function __construct(){
parent::__construct();
echo "Construction method of subclass B
";
self: :myFun();
}
function myfun(){
echo "A normal method myFun()
";
}
}
$obj= new A();
$obj=new B();
?>

The functions of self and $this are very similar, but they are not the same. $this cannot refer to static members and constants. self is more like the class attribute, and $this is more like the instance itself.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327493.htmlTechArticleLet’s talk about parent and self first: Copy the code as follows: ?php /* * Created by YinYiNiao */ class A{ function __construct(){ echo "Constructor method of base class Abr /"; } } class B extends A{ function...
Statement:
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