1 | <?php |
||
15 | class Session |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Holds the session's username. |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $username; |
||
23 | |||
24 | /** |
||
25 | * Holds this user's group. |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $group; |
||
29 | |||
30 | /** |
||
31 | * Holds the user's trusted IPs. |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $ips = null; |
||
35 | |||
36 | /** |
||
37 | * Holds some user's arbitrary data. |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $data = array(); |
||
41 | |||
42 | /** |
||
43 | * Constructor will set the session for the given username. |
||
44 | * |
||
45 | * @param string $username |
||
46 | * @param string|null $group |
||
47 | */ |
||
48 | public function __construct($username, $group = null) |
||
55 | |||
56 | /** |
||
57 | * Returns the username. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | public function getUsername() |
||
65 | |||
66 | /** |
||
67 | * Returns the user's group. |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | public function getGroup() |
||
75 | |||
76 | /** |
||
77 | * Sets the user's group. |
||
78 | * |
||
79 | * @param string $group |
||
80 | * @return void |
||
81 | */ |
||
82 | public function setGroup($group) |
||
86 | |||
87 | /** |
||
88 | * Returns the trusted IPs. |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | public function getTrustedIps() |
||
96 | |||
97 | /** |
||
98 | * Sets the trusted IPs. |
||
99 | * |
||
100 | * @param array $ips |
||
101 | * @return void |
||
102 | */ |
||
103 | public function setTrustedIps(array $ips=null) |
||
107 | |||
108 | /** |
||
109 | * Check if the specified user data is set. |
||
110 | * |
||
111 | * @param string $group |
||
112 | * @return boolean |
||
113 | */ |
||
114 | public function hasTrustedIps() |
||
118 | |||
119 | /** |
||
120 | * Adds arbitrary session data. |
||
121 | * |
||
122 | * @param string $group |
||
123 | * @return void |
||
124 | */ |
||
125 | public function addData($key, $value) |
||
129 | |||
130 | /** |
||
131 | * Checks wether the specified key is set in the session dataset. |
||
132 | * |
||
133 | * @param string $group |
||
134 | * @return boolean |
||
135 | */ |
||
136 | public function hasData($key) |
||
140 | |||
141 | /** |
||
142 | * Returns the specified data -- or the whole dataset if null. |
||
143 | * |
||
144 | * @param string $key |
||
145 | * @return mixed|null |
||
146 | */ |
||
147 | public function getData($key=null) |
||
153 | |||
154 | } |
||
155 |
Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.
To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.
The function can be called with either null or an array for the parameter
$needle
but will only accept an array as$haystack
.