__toString

<?php
    class TestClass
    {
        public $foo;

        public function __construct($foo) {
        $this->foo = $foo;
        }

        public function __toString() {
        return $this->foo;
        }
    }

    $class = new TestClass('Hello'); 

    //直接輸出對象
    echo $class;
?>


Hello
本站公眾號
   歡迎關注本站公眾號,獲取更多信息