Detailed explanation of php self and $this_PHP Tutorial

WBOY
Release: 2016-07-21 15:08:15
Original
945 people have browsed it

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...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!