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

标签 php static magic-methods

当我调用 self::$parameter = 1; 时,__set 没有被调用。

有解决办法吗?

最佳答案

来自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.

所以,我恐怕不会。

关于php - 如何使 __set 也适用于 PHP 中的静态操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2431056/

相关文章:

php - 使用 GD 为 iPhone OS 4.1 编译 PHP

java - 在 Java 中使用静态变量和方法的好处

c# - 抽象类中的静态属性

java - 如何扩展实现接口(interface)的枚举的静态方法?

php - 使用php插入mysql

php - mysql查询中使用目录函数

php - MVC 简单从数据库中选择计数并显示解释

php - __get() 和 __set() 的最佳实践

php - 除了更少的代码外,使用 __get/__set 代替传统的 getter/setter 方法是否有优势?