<?php
ini_set('display_errors',true);
error_reporting(E_ALL);
class A{
const HEHE="hello";
function show(){
echo static::HEHE;
}
}
$a=new A();
$a->show();
正常输出 hello
,没有报错
php版本为5.5.9
之所以发现这个,是因为Zend框架里就是这么用的。。
<?php
ini_set('display_errors',true);
error_reporting(E_ALL);
class A{
const HEHE="hello";
function show(){
echo static::HEHE;
}
}
$a=new A();
$a->show();
正常输出 hello
,没有报错
php版本为5.5.9
之所以发现这个,是因为Zend框架里就是这么用的。。
2 回答1.3k 阅读✓ 已解决
2 回答819 阅读✓ 已解决
1 回答893 阅读✓ 已解决
1 回答1k 阅读✓ 已解决
2 回答878 阅读
1 回答870 阅读
1 回答800 阅读
这里的
static
是php面向对象的延迟绑定功能。上面代码中,B继承了A。执行一下看看结果:
关于延迟绑定相关内容,可以参考官方文档 Late Static Bindings。