Created
May 5, 2014 14:34
-
-
Save igstan/87154e85ffc5f2fe30e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace acme; | |
function array_key_exists($key, $a) { | |
if ($a instanceof \ArrayAccess) { | |
return $a->offsetExists($key); | |
} else { | |
return \array_key_exists($key, $a); | |
} | |
} | |
class ArrayWrapper extends \ArrayObject { | |
public function offsetExists($key) { | |
echo "this will be printed\n"; | |
return parent::offsetExists($key); | |
} | |
} | |
$a = new ArrayWrapper(array('foo' => 1)); | |
var_dump(array_key_exists('foo', $a)); // bool(true) | |
var_dump(array_key_exists('bar', $a)); // bool(false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment