自己写框架的时候会出现默认控制器和方法都是index的时候,执行两次分析

1,原因:

 

php5在控制器中会先执行__construct()方法,但在php4中不会执行,于是出现两次index结果的输出
 

2,解决方法:

  

<?php

class Index extends Controller{

 

 public function __construct(){

  parent::__construct();

 }

 

 public function index(){	 //这里会进行两次输出,因为先执行__contruct()方法,而在php4中不会执行

  echo "默认控制器和默认方法";

 }

}

 

你可能感兴趣的:(index)