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';
Suggested Answer: B
Get Premium 200-710 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
12 comments · newest first
DE
Detra
2 months ago
But array_key_exists checks the array, not the object. So, B) false makes sense.
LO
Lonna
2 months ago
I feel it's A) true because of the class implementation.
JO
Josphine
2 months ago
I think the answer is B) false.
YO
Yolande
3 months ago
So, it's false? That's surprising!
NA
Naomi
3 months ago
Just because offsetExists returns true doesn't mean it applies here.
JU
Justine
3 months ago
Wait, are you sure? I thought it might be true.
AL
Alfred
3 months ago
I agree, false is the output.
DO
Domitila
3 months ago
It's definitely going to be false.
LO
Louis
3 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.
WI
Willard
4 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.
JA
Jamika
4 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.
GL
Glory
4 months ago
I think the output should be 'true' because the offsetExists method always returns true.