PHP 中 static 和 self 的区别
来源:互联网 发布:合肥大数据产业峰会 编辑:程序博客网 时间:2024/05/20 08:43
PHP 中 static 和 self 的区别
使用 self:: 或者 __CLASS__ 对当前类的静态引用,取决于定义当前方法所在的类:
使用 static:: 不再被解析为定义当前方法所在的类,而是在实际运行时计算的。也可以称之为“静态绑定”,因为它可以用于(但不限于)静态方法的调用。
静态绑定是PHP 5.3.0,增加的一个功能 用于在继承范围内引用静态调用的类
简单通俗的来说,
self就是写在哪个类里面, 实际调用的就是这个类.
static代表使用的这个类, 就是你在父类里写的static,然后被子类覆盖,使用的就是子类的方法或属性
请看列子
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
class
Person
{
public
static
function
name()
{
echo
"xiaosan"
;
echo
"<br />"
;
}
public
static
function
callself()
{
self::name();
}
public
static
function
callstatic()
{
static
::name();
}
}
class
Man
extends
Person
{
public
static
function
name()
{
echo
"gaojin"
;
echo
"<br />"
;
}
}
Man::callself();
// output: xiaosan
Man::callstatic();
// output: gaojin
?>
0 0
- PHP中 static 和 self 的区别
- PHP 中 static 和 self 的区别
- PHP中SELF和STATIC的区别
- 【PHP】PHP中static和self的区别
- 关于PHP中static和self的区别
- PHP中new static() 和 new self() 的区别
- PHP中this,self和static的区别
- PHP中new self()和new static()的区别探究
- PHP类中static 和self的使用区别
- 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的使用区别
- PHP中static关键字以及与self关键字的区别
- OSTaskStatHook()
- 378. Kth Smallest Element in a Sorted Matrix
- NOJ_1012
- gdb调试利器的学习
- 【Github教程】史上最全github使用方法:github入门到精通
- PHP 中 static 和 self 的区别
- 【Redis】缓冲之Redis简介
- php可逆加密函数
- 文件指针 FILE 的底层实现
- 【linux】记录一个配色方案putty
- 线性回归、梯度下降(Linear Regression、Gradient Descent)
- AWR视图
- 初识导函数——研究圆面积与周长的关系
- 练习题 No.9 01背包问题