在PHP中将对象转换为字符串 [英] Convert an Object to a String in PHP
问题描述
我想在PHP中将对象转换为字符串.具体来说,我尝试获取mysql查询响应,并尝试将其转换为可以写入文件并稍后使用的内容.
当然,当您尝试将对象写入文件时,PHP会大喊:可捕获的致命错误:无法在..... 中将类DB_result的对象转换为字符串.>
或者,如果还有其他方法可以将mysql查询的结果写入文件,则也可以.我正在玩一个自制缓存项目:)
也许序列化?它将获取一个对象/数组,并将其转换为字符串(随后可以将其反序列化)
I want to convert an Object into a String in PHP. Specifically, I'm trying to take a mysql query response, and I'm trying to convert it into something I can write to a file and use later.
Of course, when you try to write an Object to a file, PHP appropriately yells: Catchable fatal error: Object of class DB_result could not be converted to string in .....
Alternatively, if there is some other way of writing the result of a mysql query to a file, that works too. I'm playing around with a home-brewed caching project :)
Maybe serializing? It will take an object/array and convert it to a string (which can then be un-serialized back later)
这篇关于在PHP中将对象转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!