I would like to instanciate every field of my PHP class at the same time. So far, I have tried using list. Here is my code below (which doesn’t work). Any help would be gladly accepted.
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();
1 Answer