Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

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
Nu
12 hours ago
Wait, why would it output 2 without changes?
upvoted 0 times
...
Karima
6 days ago
No way, it should work as is!
upvoted 0 times
...
Pearly
11 days ago
I think line A should be modified instead.
upvoted 0 times
...
Lashanda
16 days ago
Line C needs to change to return a reference.
upvoted 0 times
...
Merrilee
21 days 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
27 days 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
1 month 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
1 month ago
I remember that the code should output 2 without any changes, so I think option A is correct.
upvoted 0 times
...
Osvaldo
1 month ago
I don't think we need to change anything; the code should output 2 as is, right?
upvoted 0 times
...
Florinda
2 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
2 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
2 months ago
I think the code actually outputs 0 because the array is empty when we call count.
upvoted 0 times
...

Save Cancel