1 | <?php |
||
38 | class PropertyAccessor extends RawPropertyAccessor |
||
39 | { |
||
40 | /** |
||
41 | * Reflection information about the composite being accessed |
||
42 | * |
||
43 | * @var ReflectionComposite |
||
44 | */ |
||
45 | protected $reflect; |
||
46 | |||
47 | /** |
||
48 | * Creates the PropertyAccessor for the given object, using the |
||
49 | * given reflection information |
||
50 | * |
||
51 | * @param object $object The object to access |
||
52 | * @param ReflectionComposite $reflect Reflection information about |
||
53 | * the composite |
||
54 | */ |
||
55 | 30 | public function __construct($object, ReflectionComposite $reflect) |
|
61 | |||
62 | /** |
||
63 | * Initializes the given object with the given parameters, enforcing |
||
64 | * the constructor requirements and auto building any left overs |
||
65 | */ |
||
66 | 13 | public function constructObject(...$args) |
|
112 | |||
113 | /** |
||
114 | * Builds a property automatically |
||
115 | * |
||
116 | * @param ReflectionProperty $property The property to build |
||
117 | */ |
||
118 | 4 | protected function buildProperty(ReflectionProperty $property) |
|
130 | |||
131 | /** |
||
132 | * Returns the value of the property |
||
133 | * |
||
134 | * @param string $property The name of the property to get |
||
135 | * @return mixed The value of the property |
||
136 | */ |
||
137 | 9 | public function getValue(string $property) |
|
141 | |||
142 | /** |
||
143 | * Sets the value of a property, enforcing datatype requirements |
||
144 | * |
||
145 | * @param string $property The name of the property to set |
||
146 | * @param mixed $value The value to set |
||
147 | */ |
||
148 | 11 | public function setValue(string $property, $value) |
|
149 | { |
||
150 | 11 | if (!$this->reflect->properties->containsKey($property)) |
|
|
|||
151 | { |
||
152 | throw new CannotWritePropertyException |
||
153 | ( |
||
154 | get_class($this->object), $property |
||
155 | ); |
||
156 | } |
||
157 | |||
158 | 11 | $this->setAnyValue |
|
159 | ( |
||
160 | 11 | $this->reflect->properties[$property], |
|
161 | 11 | $value |
|
162 | ); |
||
163 | 6 | } |
|
164 | |||
165 | /** |
||
166 | * Sets the value of a property, enforcing datatype requirements |
||
167 | * |
||
168 | * @param ReflectionProperty $property The property to set |
||
169 | * @param mixed $value The value to set |
||
170 | */ |
||
171 | 17 | protected function setAnyValue(ReflectionProperty $property, $value) |
|
197 | |||
198 | /** |
||
199 | * Attempts to set a property which expects a scalar value |
||
200 | * |
||
201 | * @param ReflectionProperty $property The property to set |
||
202 | * @param ScalarType $valueType The scalar type |
||
203 | * @param mixed $value The value to set |
||
204 | */ |
||
205 | 4 | private function setScalarValue |
|
236 | |||
237 | /** |
||
238 | * Throws an IlleglPropertyTypeException |
||
239 | * |
||
240 | * @param ReflectionProperty $property The property being set |
||
241 | * @param AbstractType $valueType The value being set |
||
242 | */ |
||
243 | 2 | private function throwError |
|
257 | } |
||
258 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: