1

我正在尝试设置属性并将其用于另一个功能。

我有

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->emailbuildName 方法,因为this->email在方法中定义buildemail。我需要使用 switch,因为每种方法都有很多代码。有没有办法做到这一点?

4

2 回答 2

0

你为什么不调用$employee->getEmail()你的buildName方法而不是依赖它$email呢?

还:

    case 'Name':
        $this->buildName($employee);
    case 'Numbers':
        $this->buildNumbers($employee);
      break;

buildName如果返回“名称” ,buildNumbers它们都会运行。$employee->getInfoType()你在break;两者之间缺少一个。

于 2013-02-07T18:51:48.257 回答
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(). 
}

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

于 2013-02-07T19:06:33.223 回答