U.S. Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Zend 200-710 Exam - Topic 6 Question 100 Discussion

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());
C) Line B, to: public function &getX() {
A) No changes needed, the code would output 2 as is
B) Line A, to: protected &$x = array();
D) Line C, to: return &$this->x;
E) Line D, to: $a =& new A();

Zend 200-710 Exam - Topic 6 Question 100 Discussion

Actual exam question for Zend's 200-710 exam
Question #: 100
Topic #: 6
[All 200-710 Questions]

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());

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Joaquin
11 hours ago
I doubt that, it seems like a reference issue.
upvoted 0 times
...
Nu
2 months ago
Wait, why would it output 2 without changes?
upvoted 0 times
...
Karima
2 months ago
No way, it should work as is!
upvoted 0 times
...
Pearly
2 months ago
I think line A should be modified instead.
upvoted 0 times
...
Lashanda
2 months ago
Line C needs to change to return a reference.
upvoted 0 times
...
Merrilee
2 months ago
I feel like line C might need to change, but I'm not confident that it would affect the output to be 2.
upvoted 0 times
...
Naomi
2 months ago
I practiced a similar question where returning by reference was crucial, but I can't recall if it applies here.
upvoted 0 times
...
Noelia
3 months ago
I'm not entirely sure, but I think changing line B to return by reference might help, though it seems unnecessary.
upvoted 0 times
...
Helene
3 months ago
I remember that the code should output 2 without any changes, so I think option A is correct.
upvoted 0 times
...
Osvaldo
3 months ago
I don't think we need to change anything; the code should output 2 as is, right?
upvoted 0 times
...
Florinda
3 months ago
I'm not entirely sure, but I feel like line A might need to be changed to make the array accessible.
upvoted 0 times
...
Frankie
3 months ago
I remember a similar question where we had to modify the return type of a function. Maybe changing line B to return by reference could help?
upvoted 0 times
...
Julene
3 months ago
I think the code actually outputs 0 because the array is empty when we call count.
upvoted 0 times
...

Save Cancel