/
qobject.php
67 lines (66 loc) · 1.77 KB
/
qobject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
// qobject.php -- HotCRP helper class for quiet objects (no warnings)
// Copyright (c) 2006-2019 Eddie Kohler; see LICENSE.
class Qobject implements ArrayAccess, IteratorAggregate, Countable, JsonSerializable {
function __construct($x = null) {
if ($x) {
if (is_object($x))
$x = (array) $x;
foreach ($x as $k => $v)
$this->$k = $v;
}
}
function offsetExists($offset) {
return isset($this->$offset);
}
function& offsetGet($offset) {
$x = null;
if (property_exists($this, $offset))
$x =& $this->$offset;
return $x;
}
function offsetSet($offset, $value) {
$this->$offset = $value;
}
function offsetUnset($offset) {
unset($this->$offset);
}
function getIterator() {
return new ArrayIterator(get_object_vars($this));
}
function __set($name, $value) {
$this->$name = $value;
}
function& __get($name) {
$x = null;
if (property_exists($this, $name))
$x =& $this->$name;
return $x;
}
function __isset($name) {
return isset($this->$name);
}
function __unset($name) {
unset($this->$name);
}
function get($name, $default = null) {
if (property_exists($this, $name))
$default = $this->$name;
return $default;
}
function count() {
return count(get_object_vars($this));
}
function jsonSerialize() {
return get_object_vars($this);
}
function make_array() {
return get_object_vars($this);
}
function make_object() {
return (object) get_object_vars($this);
}
function contains($key) {
return property_exists($this, $offset);
}
}