1 | <?php |
||
49 | class PropertyList implements PropertyListInterface |
||
50 | { |
||
51 | /** |
||
52 | * Property values |
||
53 | * |
||
54 | * @var array[] |
||
55 | */ |
||
56 | protected $values = []; |
||
57 | /** |
||
58 | * Property names |
||
59 | * |
||
60 | * @var IriInterface[] |
||
61 | */ |
||
62 | protected $names = []; |
||
63 | /** |
||
64 | * Name cursor mapping |
||
65 | * |
||
66 | * @var int[] |
||
67 | */ |
||
68 | protected $nameToCursor = []; |
||
69 | /** |
||
70 | * Internal cursor |
||
71 | * |
||
72 | * @var int |
||
73 | */ |
||
74 | protected $cursor = 0; |
||
75 | |||
76 | /** |
||
77 | * Return the current property values |
||
78 | * |
||
79 | * @return array Property values |
||
80 | */ |
||
81 | 8 | public function current() |
|
85 | |||
86 | /** |
||
87 | * Move forward to next element |
||
88 | */ |
||
89 | 8 | public function next() |
|
93 | |||
94 | /** |
||
95 | * Return the current IRI key |
||
96 | * |
||
97 | * @return IriInterface IRI key |
||
98 | */ |
||
99 | 1 | public function key() |
|
103 | |||
104 | /** |
||
105 | * Checks if current position is valid |
||
106 | * |
||
107 | * @return boolean The current position is valid |
||
108 | */ |
||
109 | 8 | public function valid() |
|
113 | |||
114 | /** |
||
115 | * Rewind the Iterator to the first element |
||
116 | */ |
||
117 | 8 | public function rewind() |
|
121 | |||
122 | /** |
||
123 | * Unset a property |
||
124 | * |
||
125 | * @param IriInterface|string $iri IRI |
||
126 | * @throws ErrorException |
||
127 | */ |
||
128 | 1 | public function offsetUnset($iri) |
|
136 | |||
137 | /** |
||
138 | * Return the number of properties |
||
139 | * |
||
140 | * @return int Number of properties |
||
141 | */ |
||
142 | 5 | public function count() |
|
146 | |||
147 | /** |
||
148 | * Return an array form |
||
149 | * |
||
150 | * @return array Array form |
||
151 | */ |
||
152 | 1 | public function toArray() |
|
162 | |||
163 | /** |
||
164 | * Add a property |
||
165 | * |
||
166 | * @param PropertyInterface $property Property |
||
167 | */ |
||
168 | 11 | public function add(PropertyInterface $property) |
|
180 | |||
181 | /** |
||
182 | * Return whether a property exists |
||
183 | * |
||
184 | * @param IriInterface|string $iri IRI |
||
185 | * @return boolean Property exists |
||
186 | */ |
||
187 | 11 | public function offsetExists($iri) |
|
191 | |||
192 | /** |
||
193 | * Set a particular property |
||
194 | * |
||
195 | * @param IriInterface|string $iri IRI |
||
196 | * @param array $value Property values |
||
197 | */ |
||
198 | 11 | public function offsetSet($iri, $value) |
|
206 | |||
207 | /** |
||
208 | * Get a particular property |
||
209 | * |
||
210 | * @param IriInterface|string $iri IRI |
||
211 | * @return array Property values |
||
212 | */ |
||
213 | 5 | public function &offsetGet($iri) |
|
228 | } |
||
229 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.