PHP类中static 和self的使用区别
来源:互联网 发布:淘宝网皮衣加厚的 编辑:程序博客网 时间:2024/06/07 16:29
摘自:http://php.net/manual/en/language.oop5.late-static-bindings.php
public static function who() {
echo __CLASS__;
}
}
Limitations of self::
Static references to the current class like self:: or __CLASS__ are resolved using the class in which the function belongs, as in where it was defined:
Example #1 self:: usage
<?php
class A {
public static function who() {
echo __CLASS__;
}
public static function test() {
self::who();
}
}
class B extends A {public static function who() {
echo __CLASS__;
}
}
B::test();
?>
The above example will output:
A
===================
class A {
public static function who() {
echo __CLASS__;
}
public static function test() {
self::who();
// static::who();
}
}
A::test();
class B extends A {
public static function who() {
echo __CLASS__;
}
}
echo B::test();
如果使用关键字self运行结果: A A
如果使用关键字static运行结果:A B
static:父类访问了子类的静态方法
self: 是类内指针,指向本类,静态方法,属性
阅读全文
1 0
- PHP类中static 和self的使用区别
- PHP中 static 和 self 的区别
- PHP 中 static 和 self 的区别
- PHP中SELF和STATIC的区别
- 【PHP】PHP中static和self的区别
- PHP中static 跟self的使用区别
- 关于PHP中static和self的区别
- PHP中new static() 和 new self() 的区别
- PHP中this,self和static的区别
- PHP中new self()和new static()的区别探究
- PHP中new self()和new static()的区别
- PHP 中 new static 和 new self 的区别
- php中self与static的区别
- PHP 中 this self static 的区别
- php类中 self parent static的区别
- PHP中new static()与new self()的区别
- PHP中new static()与new self()的区别
- PHP中static关键字以及与self关键字的区别
- js中几种实用的跨域方法原理详解
- 工类下载
- SpringBoot学习(六)SpringSecurity学习
- 日常纪要
- android中动态给EditText获得焦点并弹起软键盘的方法详解
- PHP类中static 和self的使用区别
- java JAXB注解
- 医学全面云转型大势已定
- Html中CSS之去除li前面的小黑点,和ul、LI部分属性方法
- Web开发之常见端口
- Pixhawk之姿态控制篇(1)_源码算法分析
- 计算机网络 之 数据链路层
- 细数你不得不知的容器安全工具
- Toolkit 理解、单例设计理解