我想設置屬性並在另一個函數上使用它。PHP開關和類屬性問題
我
while($texts->employees()){
$employee = $employees->get();
switch($employee->getInfoType()){
case 'email':
$this->buildemail($employee);
break;
case 'Name':
$this->buildName($employee);
break;
case 'Numbers':
$this->buildNumbers($employee);
break;
}
function buildEmail($employee){
$this->email=$employee->getEmail(); //get the email.
}
function buildName($employee){
$this->Name=$this->getName(); //get the name
$this->employeeInfo=$this->email.$this->name; //combine the email and numbers.
//$this->email is '' becasue it's only defined in buildEmail().
}
function buildNumbers($employee){
$this->numbers=$this->getNumbers();
}
我似乎無法得到$this->email
在buildName方法,因爲this->email
在buildemail
方法定義。 我需要使用開關,因爲每種方法都有很多代碼。有沒有辦法做到這一點?
在調用'$ this-> buildName()'之前,您需要'switch'來調用'$ this-> buildEmail()'。 – nickb
所有這些方法都在同一個類中?你沒有在你的代碼示例中包含類的「包裝器」,這可能會讓你的問題變得混亂 – thaJeztah