开发者

PHP: Call a method on a returned class

开发者 https://www.devze.com 2022-12-20 07:44 出处:网络
I have a method which returns a class and want to 开发者_StackOverflow中文版call a method on it. Instead of

I have a method which returns a class and want to 开发者_StackOverflow中文版call a method on it. Instead of

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

I would like to write

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

Is there a syntax for this as of PHP4?

This works:

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

But I would like to manipulate the class beforehand (I do this now in getClass()).


Nope, it won't work in PHP4, this feature has been bettered in PHP5. I wonder why are you still using PHP4 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消