ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**一.Stringable接口** ``` interface Stringable { public function __toString(): string; } ```   **二.类显示实现Stringable接口** ``` class Foo implements Stringable{ public function __toString(){ return 'FooBar'; } } $foo = new Foo(); var_dump($foo instanceof Stringable); ```   **三.类隐式实现Stringable接口** ``` class Foo { public function __toString(){ return 'FooBar'; } } $foo = new Foo(); var_dump($foo instanceof Stringable); ```   **四.Stringable类型约束实例** #获取类命名空间和类名大写字串 ``` namespace php8; class Person{ public function __toString(){ return self::class; } } function mysafe(\Stringable $obj){ echo strtoupper($obj); } mysafe(new Person); ```   **配套的PHP8新特性详解视频教程,请查看以下专辑** 链接:[https://www.ixigua.com/6937490165329822219](https://www.ixigua.com/6937490165329822219)