0

我有一个方法,它返回一个类并想在它上面调用一个方法。代替

$theClass = $this->getClass();
$theClass->foo();

我想写

$this->getClass()->foo();

从 PHP4 开始有这样的语法吗?

这有效:

$this->{$this->getClassName()}->foo();

但我想事先操作类(我现在在 getClass() 中这样做)。

4

1 回答 1

1

不,它在 PHP4 中不起作用,这个功能在 PHP5 中得到了改进。我想知道你为什么还在使用 PHP4 :)

于 2010-02-19T06:38:12.140 回答