0

我想同时实例化我的 PHP 类的每个字段。到目前为止,我已经尝试使用list. 这是我下面的代码(不起作用)。任何帮助都会很乐意接受。

class Test {
  private $x;
  private $y;
  private $z;

  public function Test() {
    $fields = array($this->x, $this->y, $this->z);
    // I need $fields to be an array here.
    list($fields) = array(1, 2, 3); // It would work if $fields wasn't an array.
    echo 'x = ' . $this->x . '<br />y = ' . $this->y . '<br />z = ' . $this->z;
  }
}

new Test();
4

1 回答 1

2
list($this->x, $this->y, $this->z) = array(1, 2, 3);
于 2012-07-10T08:43:27.313 回答