$value) { if (array_key_exists($key, $this->fieldsMethod)) { $this->$key = $value; } } return $this; } /** * 设置属性 * @param $name * @param $value * @return $this */ public function __set($name, $value) { if (is_array($value)) { $value = json_encode($value, JSON_UNESCAPED_UNICODE); } if ($this->fieldsMethod && array_key_exists($name, $this->fieldsMethod)) { if (method_exists($this, $this->fieldsMethod[$name])) { call_user_func([$this, $this->fieldsMethod[$name]], $value); } else { $this->$name = (int)$value; } } return $this; } /** * 转化为数组 * @return mixed */ public function toArray() { $data = []; foreach ($this as $field => $value) { if ($field == 'fieldsMethod') { continue; } $data[$field] = $value; } return $data; } }