Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active August 29, 2015 13:59
Show Gist options
  • Save mrded/10982300 to your computer and use it in GitHub Desktop.
Save mrded/10982300 to your computer and use it in GitHub Desktop.
PHP: ArrayObject bug
<?php
$obj = new ArrayObject();
$obj['hello'] = NULL;
print 'ArrayObject<br >';
var_dump(empty($obj['hello'])); // TRUE
var_dump(isset($obj['hello'])); // FALSE
var_dump(array_key_exists('hello', $obj)); // TRUE
class Test1 extends ArrayObject {
public function offsetExists($index) {
return parent::offsetExists($index);
}
public function offsetGet($index) {
return parent::offsetGet($index);
}
}
$obj = new Test1();
$obj['hello'] = NULL;
print 'Test1<br >';
var_dump(empty($obj['hello'])); // FALSE
var_dump(isset($obj['hello'])); // TRUE
var_dump(array_key_exists('hello', $obj)); // TRUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment