当前位置:网站首页>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
边栏推荐
- 实验电镜距离测量之Matlab处理
- Thanos Receiver
- flink二開,實現了個 batch lookup join(附源碼)
- Matlab processing of distance measurement of experimental electron microscope
- JSP webshell free -- the basis of JSP
- Special topic of binary tree -- acwing 3540 Binary search tree building (use the board to build a binary search tree and output the pre -, middle -, and post sequence traversal)
- php中self和static在方法中的区别
- Use of vscode tool
- Implement custom drawer component in quick application
- 【深入浅出玩转FPGA学习3-----基本语法】
猜你喜欢
How to implement tabbar title bar with list component
首份中国企业敏捷实践白皮书发布| 附完整下载
[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
From Read and save in bag file Jpg pictures and PCD point cloud
Uncover the secrets of Huawei application market application statistics
华为游戏初始化init失败,返回错误码907135000
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
Thanos Receiver
集成学习概览
Hdu1236 ranking (structure Sorting)
随机推荐
Read H264 parameters from mediarecord recording
计算序列之和
php中self和static在方法中的区别
Thanos Receiver
Hdu1236 ranking (structure Sorting)
How to implement tabbar title bar with list component
Flink two Open, implement Batch Lookup join (attached source)
【深入浅出玩转FPGA学习4----漫谈状态机设计】
[paid promotion] collection of frequently asked questions, recommended list FAQ
UVM learning - object attribute of UVM phase
JSP webshell free -- webshell free
二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)
UWA report uses tips. Did you get it? (the fourth bullet)
Special topic of binary tree -- acwing 3540 Binary search tree building (use the board to build a binary search tree and output the pre -, middle -, and post sequence traversal)
K-d tree and octree of PCL
PCL extracts a subset from a point cloud
MySQL lethal serial question 3 -- are you familiar with MySQL locks?
【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
Implement custom drawer component in quick application
PCL 投影点云