Problem:
Since PHP 5.4 this notice appears when an array is compared as the string "array". The problem is in the file includes/entity.inc in the method cacheGet which gathers items from a static cache.
On line 369 it uses array_assoc_diff which compares the array indexes and values and returns the difference of the two arrays. Unfortunately it doesn't do this recursively meaning if it is a multidimensional array it will use "array" as a string and compare it with the other array. This is what causes the notice to occur.
It seems that the code is flawed and not performing the proper function get a given item from the cache.
First Solution:
The first solution I came up with to resolve this issue was to loop through each item of the condition and use the key of the conditions to check if the entity value for that key isset. If it it isn't set then there is a difference. This would mean that the entities with that key would be unset. I don't like using nested foreach loops though this came to me as the most immediate solution to resolve the problem.
The fix was to replace lines 369 to 371:
if (array_diff_assoc($conditions, $entity_values)) {
unset($entities[$entity->{$this->idKey}]);
}
With this piece of code:
foreach ($conditions as $key=>$values) {
if (!isset($entities[$key])) {
unset($entities[$entity->{$this->idKey}]);
}
elseif ($conditions[$key] !== $entity_values[$key])
{
unset($entities[$entity->{$this->idKey}]);
}
}
Second Solution:
A second thought I've had is to add a new function that has a similar functionality as the php function array_diff_assoc except that it does the comparison recursively. While looking through the on-line PHP manual I found a function that would accomplish that.
Place this at top of entity.inc after the opening php tags:
function array_diff_assoc_recursive($array1, $array2) {
$difference=array();
foreach($array1 as $key => $value) {
if( is_array($value) ) {
if( !isset($array2[$key]) || !is_array($array2[$key]) ) {
$difference[$key] = $value;
} else {
$new_diff = array_diff_assoc_recursive($value, $array2[$key]);
if( !empty($new_diff) )
$difference[$key] = $new_diff;
}
} else if( !array_key_exists($key,$array2) || $array2[$key] !== $value ) {
$difference[$key] = $value;
}
}
return $difference;
}
Replace what you see on line 369 from:
if (array_diff_assoc($entity_values, $conditions)) {
With this code:
if (array_diff_assoc_recursive($entity_values, $conditions)) {