PHP 8.4.1 Released!

Stringable::__toString

(PHP 8)

Stringable::__toString从对象中获取字符串表示

说明

public Stringable::__toString(): string

参数

此函数没有参数。

返回值

返回对象的 string 表示。

参见

添加备注

用户贡献的备注 1 note

up
0
zikro32 at gmail dot com
3 months ago
__toString() magic method is not intended to be called directly.

Instead, it defines what is returned when the object is cast to string, either explicitly casting with:

(string)$element

Or implicitly, when used in certain contexts which would cause a conversion to string.

If you really want to explicitly call a method to convert an object to string, then you can just create a public toString method and call that, avoid using the magic __toString directly if no casting is needed.
To Top