为什么name
常量在静态函数f2()
中无法识别?为什么const在静态函数中是未定义的?
class Foo {
protected static function f1($s) {
echo "doing $s";
}
}
class Bar extends Foo {
const name = 'leo';
public static function f2() {
Foo::f1(name);
}
}
$bar = new Bar();
$bar->f2();
我得到以下错误:
Notice: Use of undefined constant name - assumed 'name' in ...
我在做什么错?
另请参见[我试图在此错误消息的原因的规范答案](http://stackoverflow.com /问题/ 2941169 /什么,做最PHP-错误消息通知 - 使用 - 的 - 未定义恒定均值/ 8025500#8025500)。 – 2011-11-06 06:52:06