求大佬解释,为什么Thinkphp在控制器里使用同名方法不会被视为构造函数去覆盖继承了的Controller的 __construct ?
这是用原生的php写的
class Base{
public function __construct(){
echo 1;
}
}
class Index extends Base{
public function index(){
echo 2;
}
}
$index = new Index();
$index->index();输出 结果为 22;这是用tp的框架写的
namespace think;
class Controller
{
/**
* 构造方法
* @access public
* @param Request $request Request 对象
*/
public function __construct()
{
echo 1;
}
}
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
public function index()
{
echo 2;
}
}输出结果为12求大佬帮助啊!!!!!!!!!!!!!!!!
tp是怎么做到的啊 大佬么
答案是
自 PHP 5.3.3 起,在命名空间中,与类名同名的方法不再作为构造函数。这一改变不影响不在命名空间中的类
@雨沫听风 @somto 两位大佬 多谢,最佳答案,好像被我弄错了。
最佳答案