PHP:在返回的类上调用方法

发布于 2024-08-22 04:19:12 字数 336 浏览 6 评论 0原文

我有一个方法返回一个类并想调用它的方法。而不是

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

我想写

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

PHP4 是否有这样的语法?

这是可行的:

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

但我想事先操作该类(我现在在 getClass() 中执行此操作)。

I have a method which returns a class and want to 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()).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清引 2024-08-29 04:19:12

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文