nerdexam
Zend

200-550 · Question #84

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 /…

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 A, 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

(35 responses)
  • A
    3% (1)
  • B
    3% (1)
  • C
    83% (29)
  • E
    11% (4)

Community Discussion

No community discussion yet for this question.

Full 200-550 Practice