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 4 Question 108 Discussion

What is the output of the following code?class Foo Implements ArrayAccess {function offsetExists($k) { return true;}function offsetGet($k) {return 'a';}function offsetSet($k, $v) {}function offsetUnset($k) {}}$x = new Foo();echo array_key_exists('foo', $x)?'true':'false';
B) false
A) true

Zend 200-710 Exam - Topic 4 Question 108 Discussion

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

What is the output of the following code?

class Foo Implements ArrayAccess {

function offsetExists($k) { return true;}

function offsetGet($k) {return 'a';}

function offsetSet($k, $v) {}

function offsetUnset($k) {}

}

$x = new Foo();

echo array_key_exists('foo', $x)?'true':'false';

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

0/2000 characters
Detra
16 days ago
But array_key_exists checks the array, not the object. So, B) false makes sense.
upvoted 0 times
...
Lonna
22 days ago
I feel it's A) true because of the class implementation.
upvoted 0 times
...
Josphine
27 days ago
I think the answer is B) false.
upvoted 0 times
...
Yolande
1 month ago
So, it's false? That's surprising!
upvoted 0 times
...
Naomi
1 month ago
Just because offsetExists returns true doesn't mean it applies here.
upvoted 0 times
...
Justine
1 month ago
Wait, are you sure? I thought it might be true.
upvoted 0 times
...
Alfred
2 months ago
I agree, false is the output.
upvoted 0 times
...
Domitila
2 months ago
It's definitely going to be false.
upvoted 0 times
...
Louis
2 months ago
I feel like the answer is 'true' because of the way offsetExists is defined, but I could be mixing it up with another concept.
upvoted 0 times
...
Willard
2 months ago
I practiced a similar question where implementing ArrayAccess was involved, and I think it might return 'false' since the key 'foo' isn't actually set.
upvoted 0 times
...
Jamika
2 months ago
I'm not entirely sure, but I remember something about array_key_exists checking if a key exists in an array, and I'm confused if it applies here.
upvoted 0 times
...
Glory
2 months ago
I think the output should be 'true' because the offsetExists method always returns true.
upvoted 0 times
...

Save Cancel