如何使 __set 也适用于 PHP 中的静态操作?

发布于 2024-08-25 01:21:47 字数 77 浏览 4 评论 0原文

当我调用 self::$parameter = 1; 时,不会调用 __set

有办法解决吗?

When I call self::$parameter = 1; the __set is not called.

Is there a way to workaround?

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

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

发布评论

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

评论(1

梦冥 2024-09-01 01:21:47

来自手册

属性重载仅适用于对象上下文。这些魔术方法不会在静态上下文中被触发。因此,这些方法不应声明为静态。从 PHP 5.3.0 开始,如果其中一种神奇重载方法被声明为静态,则会发出警告。

所以,恐怕不是。

From the manual:

Property overloading only works in object context. These magic methods will not be triggered in static context. Therefore these methods should not be declared static. As of PHP 5.3.0, a warning is issued if one of the magic overloading methods is declared static.

So, I'm afraid not.

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