php中的错误分析
为什么??错误在哪里?缺少php中的错误分析,php,Php,为什么??错误在哪里?缺少功能: Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE on line 26 public function\u构造($nm、$sur、$addr、$bp、$pr、$bd、$sx、$cs)您忘记将u构造()声明为函数。更正: public function __construct($nm,$sur,$addr,$bp,$pr,$bd,$sx,$cs) <-- line 26
功能
:
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE on line 26
public function\u构造($nm、$sur、$addr、$bp、$pr、$bd、$sx、$cs)您忘记将u构造()声明为函数。更正:
public function __construct($nm,$sur,$addr,$bp,$pr,$bd,$sx,$cs) <-- line 26
另外,将这么多参数传递到构造函数中不是一个好主意。我建议实现一个工厂,并传入一个数组:
// Bad (missing function)
public __construct($nm,$sur,$addr,$bp,$pr,$bd,$sx,$cs)
// Good
public function __construct($nm,$sur,$addr,$bp,$pr,$bd,$sx,$cs)
public\uuu结构
必须是public function\uu结构
尝试使用:
// Factory
public static function getPatient(array $array)
{
$patient = new Patient();
if (array_key_exists('name', $array) {
$patient->setName($array['name']);
}
if (array_key_exists('surname', $array) {
$patient->setSurname($array['surname']);
}
return $patient;
}
// Calling code looks something like
$patient = new Patient(
array(
'name' => $row['name'],
'surname' => $row['surname']
)
);
// Or you can simply hydrate the object after you execute your query
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$patient = new Patient();
$patient->setName($row['name']);
$patient->setSurname($row['surname']);
}
公共功能构造(……不应鼓励他放弃范围解析。
// Bad (missing function)
public __construct($nm,$sur,$addr,$bp,$pr,$bd,$sx,$cs)
// Good
public function __construct($nm,$sur,$addr,$bp,$pr,$bd,$sx,$cs)
// Factory
public static function getPatient(array $array)
{
$patient = new Patient();
if (array_key_exists('name', $array) {
$patient->setName($array['name']);
}
if (array_key_exists('surname', $array) {
$patient->setSurname($array['surname']);
}
return $patient;
}
// Calling code looks something like
$patient = new Patient(
array(
'name' => $row['name'],
'surname' => $row['surname']
)
);
// Or you can simply hydrate the object after you execute your query
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$patient = new Patient();
$patient->setName($row['name']);
$patient->setSurname($row['surname']);
}
public function __construct(...