php的类里可以有两个构造函数?

 class ecs_error
{
    var $_message   = array();
    var $_template  = '';
    var $error_no   = 0;

    /**
     * 构造函数
     *
     * @access  public
     * @param   string  $tpl
     * @return  void
     */
    function __construct($tpl)
    {
        $this->ecs_error($tpl);
    }

    /**
     * 构造函数
     *
     * @access  public
     * @param   string  $tpl
     * @return  void
     */
    function ecs_error($tpl)
    {
        $this->_template = $tpl;
    }

已经有了一个__construct(), 还有一个跟类名同名的构造函数ecs_error();
是为了匹配不同的版本吗? 为什么要有两个构造函数?

确实是为了向下兼容,__construct() 只能被版本5及5以上识别

php4 沿袭 C++ 以类名的同名函数作为构造函数
php5 新增了 __construct 作为构造函数

由于你的类属性定义是 php4 风格的,所以可认为这个类是在 php4 基础上的扩展
并非向下兼容,而是画蛇添足

使用php5的__construct吧
php4淘汰了。

在php5以上,如果同时存在__construct 与 同名函数作为构造函数,__construct会优先于同名函数。

即__construct存在,会调用__construct,如__construct不存在,但同名函数存在,会调用同名函数

 <?php
class test{

    /*function __construct(){
        echo 'ok';  
    }*/

    function test(){
        echo 'ok1';
    }

    function run(){
        echo 'Hello World';
    }

}

$obj = new test();
$obj->run();
?>