当前位置:网站首页>The difference between self and static in PHP in methods
The difference between self and static in PHP in methods
2022-07-02 11:02:00 【kankan231】
Let's start with the last piece of code
class Father{
public static $a = 2;
public function selfTest(){
var_dump(self::$a);
}
public function staticTest(){
var_dump(static::$a);
}
}
class Son extends Father {
public static $a = 20;
}
$obj = new Son();
$obj->selfTest();
$obj->staticTest();Output :
int(2)
int(20)
Conclusion :self Express self Keyword class , That is to say, here self yes Father class ,self::$a Namely Father::$a, Although it is a subclass call selfTest Method self::$a It will not show polymorphism
static Represents the class that calls the method , here obj The class of the object is Son, be static::$a That means Son::$a, If obj The class of the object is Father class , be static::$a That means Father::$a, in other words static::$a Will show polymorphism
边栏推荐
- Luogu p1892 [boi2003] Gang (and search for variant anti set)
- 【ARK UI】HarmonyOS ETS的启动页的实现
- 1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
- (5) Gear control setting of APA scene construction
- JSP webshell免殺——JSP的基礎
- HDU1236 排名(结构体排序)
- [quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched
- One trick to quickly realize custom application titlebar
- Special topic of binary tree -- Logu p1229 traversal problem (the number of traversals in the middle order is calculated when the pre and post order traversals of the multiplication principle are know
- Shell programming 01_ Shell foundation
猜你喜欢

How to transfer event objects and user-defined parameters simultaneously in Huawei express applications

全网显示 IP 归属地,是怎么实现的?

Creation and use of unified links in Huawei applinking

从.bag文件中读取并保存.jpg图片和.pcd点云

二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)

【AGC】构建服务3-认证服务示例

Open the encrypted SQLite method with sqlcipher

如何使用IDE自动签名调试鸿蒙应用

软件产品管理系统有哪些?12个最佳产品管理工具盘点

Kustomize user manual
随机推荐
二叉树专题--【深基16.例7】普通二叉树(简化版)(multiset 求前驱 后继 哨兵法)
实验电镜距离测量之Matlab处理
Binary tree topic -- p1030 [noip2001 popularization group] find the first order
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
Luogu p4281 [ahoi2008] emergency gathering / gathering (tree doubling LCA)
Learn open62541 -- [66] UA_ Generation method of string
Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
华为AppLinking中统一链接的创建和使用
PCL projection point cloud
HDU1236 排名(结构体排序)
Filtering of PCL
Flink two Open, implement Batch Lookup join (attached source)
【深入浅出玩转FPGA学习4----漫谈状态机设计】
Leetcode 182 Find duplicate email (2022.07.01)
计算序列之和
UVM——Callback
【深入浅出玩转FPGA学习3-----基本语法】
【ARK UI】HarmonyOS ETS的启动页的实现
洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)
[AI application] Hikvision ivms-4200 software installation