Skip to content

Instantly share code, notes, and snippets.

@igstan
Created May 5, 2014 14:34
Show Gist options
  • Save igstan/f59388aeb26a43a47746 to your computer and use it in GitHub Desktop.
Save igstan/f59388aeb26a43a47746 to your computer and use it in GitHub Desktop.
<?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