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

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

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



        
10条回答
  •  生来不讨喜
    2021-01-01 10:47

    The __toString method allows a class to decide how it will react when it is treated like a string

    http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring

提交回复
热议问题