douqiao6563 2009-06-02 18:44
浏览 17
已采纳

隐式转换为字符串而不是获取“对象ID#..”

I've moved to a new webhost were we have php 5.1 instead of 5.2 that I've been using until now. I still haven't figured out if it's a php version or configuration issue.

Right now most (or all) of the classes that have __toString functions convert to "Object ID #" (like in php4) but before they all returned the correct values.

How can I fix this?

  • 写回答

2条回答 默认 最新

  • donglang6656 2009-06-02 18:51
    关注

    Apparently prior to PHP 5.2 the __toString method was only "magically" called in certain circumstances (e.g. echo() and print()). So if you are currently using __toString() in a "magical" way outside of direct output functions it will not work as expected.

    Source:

    It is worth noting that before PHP 5.2.0 the __toString method was only called when it was directly combined with echo() or print(). Since PHP 5.2.0, it is called in any string context (e.g. in printf() with %s modifier) but not in other types contexts (e.g. with %d modifier). Since PHP 5.2.0, converting objects without __toString method to string would cause E_RECOVERABLE_ERROR.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站