Possible Duplicate:
PHP ToString() equivalent
How to convert a PHP object to a string?
I'm looking for a function that can take any kind of variable (primitive, object, array, ...) and convert it to a string, for debugging purposes.
This is the best question I could find about converting objects to strings. Its answers don't seem to contain a general purpose solution that can handles all kinds of objects. I've tried (string)x, strval(x) and serialize(x), and also json_encode(x) from this answer.
(string)x and strval(x) cause Object of class Foo could not be converted to string. json_encode(x) returns an empty string for me. serialize() does work, but its output is not only textual (it contains weird "NULLs" and is a bit hard to read.
I tried search Stack Overflow for Object of class Foo could not be converted to string, but found a ton of specific question that got zero upvotes and no general solutions.
The question, again - how to pretty print / convert any php value into a string in php?