通常,当我编写 PHP 类时,我会执行以下操作:
class MyClass () {
public attribute1;
public attribute2;
public attribute3;
}
是否可以根据逻辑设置属性?
class MyClass () {
public function __construct() {
if (some condition) {
public attribute1;
attribute1 = 23;
} else {
public attribute1;
attribute1 = 55;
public attribute2;
attribute2 = 11;
}
}
}