Eclipse为我的Person对象提供了一条红线。我想知道我的代码有什么问题。我是php的新手。
class Matcher{
private $user1= new Person($firstName, $lastName, $zipCode, $hairColor, $job, $eyeColor, $height, $weight, $dateOfBirth, $children, $education, $ethnicity, $faith, $language, $bodyType);
private $user2= Person;
function __construct($user1, $user2){
$this -> user1 = $user1;
$this -> user2 = $user2;
}
}
答案 0 :(得分:1)
您应该在类构造函数中执行此操作:
class Matcher{
private $user1
private $user2;
function __construct($user1, $user2){
$this->user1 = new Person($firstName, $lastName, $zipCode, $hairColor, $job, $eyeColor, $height, $weight, $dateOfBirth, $children, $education, $ethnicity, $faith, $language, $bodyType);
$this->user2 = new Person();
}
}
但另外我没有看到为什么你在这里创建新对象,因为你在构造函数中也将其他对象(或变量)分配给属性user1
和user2
。
同样对于user2
,您的语法private $user2= Person;
不正确,没有新的运算符