Zend
200-710 · Question #108
In the following code, which line should be changed so it outputs the number 2: ``php class A { protected $x = array(); / A. / public function getX() { / B. / return $this->x; / C. / } } $a = new A();
The correct answer is C. Line B, to: public function &getX() {. See the full explanation below for the reasoning.
Question
In the following code, which line should be changed so it outputs the number 2:
class A {
protected $x = array(); /* A. */
public function getX() { /* B. */
return $this->x; /* C. */
}
}
$a = new A(); /* D. */
array_push($a->getX(), "one");
array_push($a->getX(), "two");
echo count($a->getX());
Options
- ANo changes needed, the code would output 2 as is
- BLine B, to: protected &x; array();
- CLine B, to: public function &getX() {
- DLine C, to: return &$this->x;
- ELine D, to: $a = &$new A();
How the community answered
(16 responses)- A13% (2)
- B6% (1)
- C75% (12)
- D6% (1)
Community Discussion
No community discussion yet for this question.