目前BAE的PHP执行环境不支持static::获取静态变量
以下文字参考自 http://hi.baidu.com/zxsz4085/item/0c2761a8134a0a38030a4dd5php5.3中提出的static::作用域使我们不再需要使用self::和parent::。当希望指向最终的实现类时,就可以使用static::,这个限定符会在代码执行之前立即计算出继承层次结构上最后那个类的成员。这一过程被称为延迟绑定。
好像没看出有什么用,直接在父类中new那个最终实现类的对象然后调用不就行了吗?但是如果你不知道那个最终类叫什么,覆盖
的方法实现了什么样的效果,这时候似乎就有用了。static::作用域也可以应用在静态方法上,这样从父类可以静态的调用子类的方法。
我在BAE上创建了个应用,然后新建了个版本,把index.php的内容改成如下内容:
index.php
<?php
class test_static {
public static $static_mem = "before";
public static function test() {
static::$static_mem = "after";
}
}
print "before calling function test ".test_static::$static_mem."<br/>";
test_static::test();
print "after calling function test ".test_static::$static_mem."<br/>";
?>
然后点击发布,结果发布失败,查看日志有如下一条日志(appid已被修改):
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting T_VARIABLE in code/builder/work/appidyzhdsezfxd/0/index.php on line 5
Errors parsing code/builder/work/appidyzhdsezfxd/0/index.php
可见,BAE不支持static::。
页:
[1]