function ad_object_to_array in Advertisement 7.3
Turn an object into an array, eventually also turning any embedded object.
This is done because when a object is retrieved from the cache, and a full bootstrap was not performed, class autoloading fails, and the resulting object is incomplete.
Parameters
$object: The object to be turned into the array.
Return value
array The resulting array.
3 calls to ad_object_to_array()
- ad_get_cache in ./
ad.module - Return the eventually cached results of a callback
- ad_get_destination in ./
ad.module - Return the destination URL of an ad.
- _ad_flatten in ./
ad.module - Flatten a structure into an array suitable to be the base of a cache id.
File
- ./
ad.module, line 671 - Core code for the ad module.
Code
function ad_object_to_array($object) {
static $known_objects;
if (is_object($object)) {
// Don't consider objects which can't be serialized, like Queries.
if ($object instanceof Query) {
return;
}
elseif (!empty($known_objects) && array_search(serialize($object), $known_objects)) {
return;
}
else {
// Avoid recursion.
$known_objects[] = serialize($object);
$object = (array) clone $object;
}
}
if (is_array($object)) {
$array = array();
foreach ($object as $key => $val) {
$array[$key] = ad_object_to_array($val);
}
}
else {
$array = $object;
}
return $array;
}