企业🤖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)