当前位置:网站首页>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
边栏推荐
- JVM garbage collector
- Special topic of binary tree -- acwing 1589 Building binary search tree
- 二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
- 计算序列之和
- Open the encrypted SQLite method with sqlcipher
- 二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)
- HDU1236 排名(结构体排序)
- 软件产品管理系统有哪些?12个最佳产品管理工具盘点
- [applinking practical case] share in app pictures through applinking
- 一招快速实现自定义快应用titlebar
猜你喜欢

V2X-Sim数据集(上海交大&纽约大学)

集成学习概览

flink二开,实现了个 batch lookup join(附源码)

Jsp webshell Free from killing - The Foundation of JSP

1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS

Huawei game failed to initialize init with error code 907135000
![二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)](/img/c2/bb85b681af0f78b380b1d179c7ea49.png)
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)

Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)

JSP webshell free -- the basis of JSP

二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
随机推荐
js数组常用方法
Leetcode+ 76 - 80 storm search topic
UVM factory mechanism
Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
C#中索引器
618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
PCL之滤波
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
One trick to quickly realize custom application titlebar
华为快应用中如何实现同时传递事件对象和自定义参数
一招快速实现自定义快应用titlebar
Matlab processing of distance measurement of experimental electron microscope
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
Use of vscode tool
实验电镜距离测量之Matlab处理
UVM——Callback
二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
Oracle 笔记
洛谷 P1892 [BOI2003]团伙(并查集变种 反集)