I've used this function to 'fix' objects for awhile - it seems to do a great job of conversion from private and protected objects to make them 'stdClass' where I can then see and use the data.
function fix_object( $object ) {
$dump = serialize( $object );
// print_r($dump); echo "<hr>";
$dump = str_replace('s:6:"series";r:1;','s:6:"series";s:6:"series";',$dump);
// print_r($dump); echo "<hr>";
$dump = preg_replace( '/^O:\d+:"[^"]++"/', 'O:8:"stdClass"', $dump );
$dump = preg_replace_callback( '/:\d+:"\0.*?\0([^"]+)"/', function($matches){
return ":" . strlen( $matches[1] ) . ":\"" . $matches[1] . "\"";}, $dump );
return unserialize( $dump );
}
See the line between the 'print_r($dump);' lines - that one is the only one you need to change for your own objects (I put 'hr's around the dump to give more spacing...)
In my case, as you can see, I found that the 'series' had the 'r:1' on it, which caused json_encode to give the recursion detected error.
By looking at the serialize dump, I found that and replaced it with a string (you could put anything that doesn't break the json, but be careful!)
As the part that was recursive wasn't needed (already in the object...), it didn't matter what I replaced it with.
The end result is a very nice, non-error json_encode!
echo "json series = " . json_encode(fix_object( $origObject)) . "<br>";
As stated in the comments on the question, you should be careful in using such things as blasting out 'private' or 'protected' data can be a bad thing. In some cases, though, the dev just puts everything as 'private' or 'protected' (even when it really shouldn't be....) - in those cases, this function is a lifesaver!