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.
http://www.bkjia.com/PHPjc/327493.htmlwww.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...