You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Meaning that the value of data could be any valid return value from json_decode which means it could be an array, an object, true, false, null. And of course if there are no contents, the class variable data remains undefined.
Returns the value encoded in json as an appropriate PHP type. Unquoted values true, false and null are returned as true, false and null respectively. null is returned if the json cannot be decoded or if the encoded data is deeper than the nesting limit.
If a caller uses the magic __get() method and the response data is a boolean, or an array, there will be a fatal error in that method, since it assumes that the returned data was decoded into a JSON object.
Proposed resolutions
Either:
Increase flexibility: implement __get($name) such that the method checks if data is an array or object and then returns (if array) the value of the array at $name or (if object) the $name property of the object, or undefined if neither of those are the case.
Or
Increase strictness (if possible): Since this is not a general purpose library, we can instead perhaps research if the Orange Dam API in fact always returns objects. If that is the case, and it is a part of the API specification (ie, it can be trusted), we can re-type data from mixed to object and leave the __get() method as it is.
Acceptance Criteria
Callers should be able to call HTTP\Response->{$property_name} without worrying about the response data type.
The text was updated successfully, but these errors were encountered:
Description
The class variable
data
on the HTTP\Response class is type-hinted as follows:This is correct, since the data is set as follows:
Meaning that the value of
data
could be any valid return value fromjson_decode
which means it could be an array, an object, true, false, null. And of course if there are no contents, the class variabledata
remains undefined.PHP Documentation on json_decode Return Values
If a caller uses the magic
__get()
method and the response data is a boolean, or an array, there will be a fatal error in that method, since it assumes that the returned data was decoded into a JSON object.Proposed resolutions
Either:
__get($name)
such that the method checks if data is an array or object and then returns (if array) the value of the array at$name
or (if object) the$name
property of the object, or undefined if neither of those are the case.Or
data
from mixed to object and leave the__get()
method as it is.Acceptance Criteria
Callers should be able to call HTTP\Response->{$property_name} without worrying about the response data type.
The text was updated successfully, but these errors were encountered: