0
我在想,如果在我以后在其他地方使用(在下面的代码中,我将传递给insertArray()函数)的数组中声明我的成员变量是不好的约定。在这里我的代码:在数组操作中定义成员变量
class myClass{
private $ID;
private $name;
private $type;
private $catID;
private $isDefault;
private $isRequired;
function __construct($compID = 0, $catID = 0, $name = '', $type = '', $default = false, $required = false){
$myArray = array(
'name' => ($this->name = $name),
'type' => ($this->type = $type),
'catID' => ($this->catID = $catID),
'isDefault' => ($this->isDefault = $default),
'isRequired' => ($this->required = $required)
)
self::insertArray($myArray);
}
}
在$ myArray中定义我的成员变量不好吗?我非常确定在PHP中,表单的语法($ this-> value = $ value)会将$ value存储在$ this-> value中,然后仅评估为($ this-> value)。
你的代码应该工作得很好。 –