在类中创建新对象的问题


issues with creating a new object in a class

Eclipse在new下为Person对象添加了一条红线。我想知道我的代码有什么问题。我是php OOP新手。

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;
}
}

你应该在你的类构造函数中这样做:

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();
    }
}

但除此之外,我不明白为什么你在这里创建新对象,因为你在构造函数中还将其他对象(或变量)分配给属性user1user2

对于user2,您有错误的语法private $user2= Person;没有新的操作符