1 | <?php |
||
19 | class HttpHeadersBag implements \ArrayAccess, \Iterator |
||
20 | { |
||
21 | /** |
||
22 | * @var string[] |
||
23 | */ |
||
24 | private $headers; |
||
25 | |||
26 | /** |
||
27 | * Is used by the iterator feature to store a possible "false" value when the loop over the array is finished. |
||
28 | * |
||
29 | * @var mixed |
||
30 | */ |
||
31 | private $next; |
||
32 | |||
33 | 26 | public function __construct(array $headers = null) |
|
37 | |||
38 | /** |
||
39 | * @param string $name |
||
40 | * @param mixed $value |
||
41 | * @return self |
||
42 | */ |
||
43 | 3 | public function set(string $name, $value) |
|
49 | |||
50 | /** |
||
51 | * @param string $name |
||
52 | * @param mixed $default |
||
53 | * @return mixed |
||
54 | */ |
||
55 | 27 | public function get(string $name, $default = null) |
|
62 | |||
63 | /** |
||
64 | * @param string $name |
||
65 | * @param mixed $value |
||
66 | * @return self |
||
67 | */ |
||
68 | 22 | public function add(string $name, $value) |
|
81 | |||
82 | /** |
||
83 | * @param string $name |
||
84 | */ |
||
85 | public function remove(string $name) |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | 10 | public function offsetExists($offset) |
|
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | 17 | public function offsetGet($offset) |
|
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | public function offsetSet($offset, $value) |
||
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | public function offsetUnset($offset) |
||
121 | |||
122 | 14 | public function current() |
|
126 | |||
127 | 14 | public function next() |
|
131 | |||
132 | 14 | public function key() |
|
136 | |||
137 | 14 | public function valid() |
|
141 | |||
142 | 14 | public function rewind() |
|
146 | } |
||
147 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: