当前位置:网站首页>php中self和static在方法中的区别
php中self和static在方法中的区别
2022-07-02 07:28:00 【kankan231】
先上一段代码
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();输出:
int(2)
int(20)
结论:self表示self关键字所在的类,也就是说这里的self是Father类,self::$a就是Father::$a,尽管是子类调用selfTest方法self::$a也不会表现出多态性
static表示调用该方法的类,这里obj对象的类是Son,则static::$a表示的就是Son::$a,如果obj对象的类是Father类,则static::$a表示的就是Father::$a,也就是说static::$a会表现出多态性
边栏推荐
- 点云投影图片
- 洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
- [SUCTF2018]followme
- Win11 arm系统配置.net core环境变量
- UVM——Callback
- From Read and save in bag file Jpg pictures and PCD point cloud
- Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
- Introduction to MySQL 8 DBA foundation tutorial
- Retrofit's callback hell is really vulnerable in kotlin synergy mode!
- Matlab processing of distance measurement of experimental electron microscope
猜你喜欢
![2. Hacking lab script off [detailed writeup]](/img/f3/29745761cd5ad4df84c78ac904ea51.png)
2. Hacking lab script off [detailed writeup]

Shell programming 01_ Shell foundation

Kustomize user manual

二叉树专题--AcWing 1589. 构建二叉搜索树

Use of vscode tool

Win11 arm系统配置.net core环境变量

Hdu1234 door opener and door closer (water question)

首份中国企业敏捷实践白皮书发布| 附完整下载

618 what is the secret of dominating the list again? Nike's latest financial report gives the answer

Shapiro Wilk normal analysis by SPSS
随机推荐
从.bag文件中读取并保存.jpg图片和.pcd点云
Set the playback speed during the playback of UOB equipment
简洁、快速、节约内存的Excel处理工具EasyExcel
C#中索引器
Learn open62541 -- [66] UA_ Generation method of string
Analysis of hot spots in AI technology industry
2022-06-17
JSP webshell免杀——webshell免杀
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)
从MediaRecord录像中读取H264参数
14. Code implementation of semaphore
转换YV12到RGB565图像转换,附YUV转RGB测试
2. Hacking lab script off [detailed writeup]
HDU1236 排名(结构体排序)
js promise. all
长投学堂上面的账户安全吗?
MySQL数据库远程访问权限设置
JSP webshell免殺——JSP的基礎
2022爱分析· 国央企数字化厂商全景报告
Oracle 笔记