PHP开关和类属性问题

PHP开关和类属性问题,php,Php,我正在尝试设置属性并在另一个函数上使用它 我有 while($texts->employees()){ $employee = $employees->get(); switch($employee->getInfoType()){ case 'email': $this->buildemail($employee); break; case 'Name':

我正在尝试设置属性并在另一个函数上使用它

我有

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,因为每个方法中都有很多代码。有什么方法可以做到这一点吗?

为什么不在
buildName
方法中调用
$employee->getEmail()
,而不依赖
$email
中的方法呢

此外:

如果
$employee->getInfoType()
返回“Name”,则
buildName
buildNumbers
都将运行介于两者之间。

您不能这样做吗

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

我假设每个员工都必须有一封电子邮件,对吗?

在调用
$this->buildEmail()
之前,您需要您的
开关调用
$this->buildName()
。所有这些方法都在同一个类中?您的代码示例中没有包含类“wrapper”,这可能会使您的问题令人困惑
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(). 
}