search
Homephp教程php手册深入php self与$this的详解

本篇文章是对php中的self与$this进行了详细的分析介绍,需要的朋友参考下

先谈parent与self:

复制代码 代码如下:


/*
* Created by YinYiNiao
*/
class A{
function __construct(){
echo "基类A的构造方法
";
}
}
class B extends A{
function __construct(){
parent::__construct();
echo "子类B的构造方法
";
self::myFun();
}
function myfun(){
echo "一个普通方法myFun()
";
}
}
$obj=new A();
$obj=new B();
?>


self与$this的功能极其相似,香港虚拟主机,但二者又不相同。$this不能引用静态成员和常量。self更像类本事,而$this更像是实例本身。
,香港虚拟主机,香港服务器
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor