我正在尝试设置属性并在另一个函数上使用它。
我有
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();
}
我似乎无法在buildName方法中获取$this->email
,因为this->email
方法中定义了buildemail
。
我需要使用switch,因为每种方法都有很多代码。反正有没有这样做?
答案 0 :(得分:0)
为什么不用$employee->getEmail()
方法拨打buildName
而不是依赖$email
?
此外:
case 'Name':
$this->buildName($employee);
case 'Numbers':
$this->buildNumbers($employee);
break;
如果buildName
返回“姓名”,则 buildNumbers
和$employee->getInfoType()
都会运行。你错过了两者之间的break;
。
答案 1 :(得分:0)
你不能这样做:
function buildName($employee){
$this->Name=$this->getName(); //get the name
if(null == $this->email)
$this->buildEmail($employee);
$this->employeeInfo= $this->email.$this->name; //combine the email and numbers.
//$this->email is '' becasue it's only defined in buildEmail().
}
我认为每个员工都必须收到一封电子邮件,这是正确的吗?