在类之外使用 php 的魔术方法

发布于 2024-08-30 06:14:29 字数 120 浏览 1 评论 0原文

是否可以在定义的类之外使用 PHP 魔术方法(特别是 __get())?

我想在配置文件中使用它来快速加载。配置文件有一个数组 $config,其中包含许多键。因此,我想重写 __get() 以返回数组中的键。

Is it possible to use PHP magic methods (specifically __get()) outside a defined class?

I'm wanting to use it in a configuration file for quick loading. The configuration file has a single array, $config, with many keys. Therefore, I'd like to override __get() to return the key in the array.

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

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

发布评论

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

评论(1

暮凉 2024-09-06 06:14:29

不,但您可以编写一个读取配置文件的对象,并提供 __get 方法。

No, but you could write an object that reads the config file, and provides the __get method.

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