为什么新版本得这样写?
<?phpclass Index extends Controller {
function __construct() {
parent::Controller();
}
function Index() {
echo 'Hello World';
}
}
?>
不定义__construct就会Show出两个Hello World。。?????
[ 本帖最后由 caincheung 于 2008-4-15 08:16 编辑 ] 我给你编辑了,自己看代码~ 那样写相当于2构造函数了吧?
你类名是Index,,类里边有定义了index方法(相当于构造函数~~)
里边你还申请了__construct()构造函数 php5以前的版本,构造函数的申明都是与类名相同
如:
<?php
class Index extends Controller{
//构造函数
function index(){
parent::Controller();
}
}
而在php5中,构造函数是可以这样写的
function __construct(){
}
对,楼主那个是产生了PHP5和4的兼容性问题了,不能同时使用PHP4和5的构造函数写法。
页:
[1]