Possible Duplicate:
PHP ToString() equivalent
I get this error:
Catchable fatal error: Object of class stdClass could not be converted to string
So, my question is, how do I convert an object to a string in PHP? I don't want to serialize it though.
Just a note: the code I use works in PHP 4, but not in PHP 5
Thanks!
EDIT: I resolved it myself. It was a pain, but I did it. Thanks anyway, everyone :-)
_toString() function in PHP is extensively used to convert the object related to it into string whereas the serialize() function is used to convert the object and return a string containing entire byte-stream which at later point of time is used for representation of any value that is stored in the PHP variable being ...
An object copy is created by using the clone keyword (which calls the object's __clone() method if possible). $copy_of_object = clone $object; When an object is cloned, PHP will perform a shallow copy of all of the object's properties. Any properties that are references to other variables will remain references.
We can convert Object to String in java using toString() method of Object class or String. valueOf(object) method. You can convert any object to String in java whether it is user-defined class, StringBuilder, StringBuffer or anything else.
Why do you need this string? If you just need to visualize it for debugging, you can use var_dump()
, print_r()
, or $s = print_r($var, 1);
to really make it into a string for further theming. If you need to send the object as text to somewhere else (database, Javascript code), you have a choice of serialize, json_encode, XML conversion, and many more, depending on your exact situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With