Where and why do we use __toString() in PHP?

后端 未结 10 1705
星月不相逢
星月不相逢 2021-01-01 10:34

I understand how it works but why would we practically use this?



        
10条回答
  •  死守一世寂寞
    2021-01-01 11:02

    __toString allows you to define the output when your object is converted to a string. This means that you can print the object itself, rather than the return value of a function. This is frequently more convenient. See the manual entry.

提交回复
热议问题