Echo Return construct method;

后端 未结 6 1799
有刺的猬
有刺的猬 2021-01-25 08:11

6条回答
  •  耶瑟儿~
    2021-01-25 08:49

    The constructors should not return anything.

    If you want to echo an object, you have to define how to form its string representation with the magic method __tostring:

    class DBFactory {  
         function __tostring(){  
             return 'Need to echo';
         }  
    }
    $db = new DBFactory();
    echo $db;
    

提交回复
热议问题