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
SaintSystems\OData\ODataRequest::flattenDictionary() checks if the method exits on $arrayValue. $arrayValue could be an array itself, which would cause a type error on method_exits in PHP 8.
Existing method
/**
* Flattens the property dictionaries into
* JSON-friendly arrays
*
* @param mixed $obj the object to flatten
*
* @return array flattened object
*/
protected function flattenDictionary($obj) {
foreach ($obj as $arrayKey => $arrayValue) {
if (method_exists($arrayValue, 'getProperties')) {
$data = $arrayValue->getProperties();
$obj[$arrayKey] = $data;
} else {
$data = $arrayValue;
}
if (is_array($data)) {
$newItem = $this->flattenDictionary($data);
$obj[$arrayKey] = $newItem;
}
}
return $obj;
}
I will open a pull request for the following change, where we check if $arrayValue is either a string or an object:
/**
* Flattens the property dictionaries into
* JSON-friendly arrays
*
* @param mixed $obj the object to flatten
*
* @return array flattened object
*/
protected function flattenDictionary($obj) {
foreach ($obj as $arrayKey => $arrayValue) {
if ((is_string($arrayValue) || is_object($arrayValue)) && method_exists($arrayValue, 'getProperties')) {
$data = $arrayValue->getProperties();
$obj[$arrayKey] = $data;
} else {
$data = $arrayValue;
}
if (is_array($data)) {
$newItem = $this->flattenDictionary($data);
$obj[$arrayKey] = $newItem;
}
}
return $obj;
}
The text was updated successfully, but these errors were encountered:
trent-crawford
changed the title
flattenDictionary calls method exist without first ensuring the first parameter is an object or class
flattenDictionary causes a type error in PHP 8 by calling method_exists without checking type of first parameter
Mar 3, 2023
SaintSystems\OData\ODataRequest::flattenDictionary() checks if the method exits on $arrayValue. $arrayValue could be an array itself, which would cause a type error on method_exits in PHP 8.
Existing method
I will open a pull request for the following change, where we check if $arrayValue is either a string or an object:
The text was updated successfully, but these errors were encountered: