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

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
Loren
3 days ago
Line D seems off too. We should change it to reference.
upvoted 0 times
...
Brock
8 days ago
I disagree, I feel like we need to change line C.
upvoted 0 times
...
Magnolia
13 days ago
I think A is correct. No changes needed.
upvoted 0 times
...
Noah
19 days ago
Line C seems unnecessary. Just return the array.
upvoted 0 times
...
Jerilyn
24 days ago
But what about line B? It could work too.
upvoted 0 times
...
Glenn
29 days ago
I agree, it outputs 2 without changes.
upvoted 0 times
...
Pearly
1 month ago
I think A is correct. No changes needed.
upvoted 0 times
...
Lorrie
1 month ago
Line D looks suspicious, not sure about that one.
upvoted 0 times
...
Loren
1 month ago
Definitely line A, no changes needed!
upvoted 0 times
...
Daren
2 months ago
Wait, does this really output 2 as is? Seems off.
upvoted 0 times
...
Therese
2 months ago
I think line B is the right choice!
upvoted 0 times
...
Leanna
2 months ago
Line C needs to change to return a reference.
upvoted 0 times
...
Colette
2 months ago
Definitely line A, it needs to be a reference!
upvoted 0 times
...
Mitsue
2 months ago
Wait, why would it output 2? I'm confused.
upvoted 0 times
...
Jess
3 months ago
No way, it works fine as is!
upvoted 0 times
...
Laquanda
3 months ago
I think line C is the issue here.
upvoted 0 times
...
Cherry
3 months ago
Line A needs to change to output 2.
upvoted 0 times
...
Joaquin
3 months ago
I doubt that, it seems like a reference issue.
upvoted 0 times
...
Nu
5 months ago
Wait, why would it output 2 without changes?
upvoted 0 times
...
Karima
5 months ago
No way, it should work as is!
upvoted 0 times
...
Pearly
5 months ago
I think line A should be modified instead.
upvoted 0 times
...
Lashanda
5 months ago
Line C needs to change to return a reference.
upvoted 0 times
...
Merrilee
5 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
5 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
6 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
6 months ago
I remember that the code should output 2 without any changes, so I think option A is correct.
upvoted 0 times
...
Osvaldo
6 months ago
I don't think we need to change anything; the code should output 2 as is, right?
upvoted 0 times
...
Florinda
6 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
6 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
6 months ago
I think the code actually outputs 0 because the array is empty when we call count.
upvoted 0 times
...

Save Cancel