level 1
以下代码输出错误:
<?php
class DBFactory {
function __construct(){
return 'Need to echo';
}
}
$db = new DBFactory;
echo $db;
?>
这样写不出错:
<?php
class DBFactory{
function __construct(){
return 'Need to echo';
}
}
$db = new DBFactory();
echo $db->__construct();
?>
请问为什么?谢谢!
2022年09月01日 00点09分
1
level 16
__construct是给new调用的,不是给你直接调用的,而且它不能有返回值,建议补基础
2022年09月01日 06点09分
2