@since Method available since Release 3.2.1
mixed $data:
string
protected function dataToString($data) {
$result = array();
// There seems to be no other way to check arrays for recursion
// http://www.php.net/manual/en/language.types.array.php#73936
preg_match_all('/\\n \\[(\\w+)\\] => Array\\s+\\*RECURSION\\*/', print_r($data, TRUE), $matches);
$recursiveKeys = array_unique($matches[1]);
// Convert to valid array keys
// Numeric integer strings are automatically converted to integers
// by PHP
foreach ($recursiveKeys as $key => $recursiveKey) {
if ((string) (int) $recursiveKey === $recursiveKey) {
$recursiveKeys[$key] = (int) $recursiveKey;
}
}
foreach ($data as $key => $_data) {
if (in_array($key, $recursiveKeys, TRUE)) {
$result[] = '*RECURSION*';
}
else {
if (is_array($_data)) {
$result[] = 'array(' . $this
->dataToString($_data) . ')';
}
else {
if (is_object($_data)) {
$object = new ReflectionObject($_data);
if ($object
->hasMethod('__toString')) {
$result[] = (string) $_data;
}
else {
$result[] = get_class($_data);
}
}
else {
if (is_resource($_data)) {
$result[] = '<resource>';
}
else {
$result[] = var_export($_data, TRUE);
}
}
}
}
}
return join(', ', $result);
}