0%

PHP5.3.27类名和方法名一致问题

以下代码是今天偶尔的一个想法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class test{
public $Version='PHP Version 5.3.27';
const BR='<br />';

function test(){
echo __FUNCTION__. self::BR;
echo __CLASS__. self::BR;
echo $this->Version. self::BR;
}

function __construct(){
echo __FUNCTION__. self::BR;
echo __CLASS__. self::BR;
echo $this->Version. self::BR;

}
}
$test=new test();

运行结果报错:
Strict standards: Redefining already defined constructor for class test in xxxx
把析构和方法换一下位置,运行结果是正常的.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class test{
public $Version='PHP Version 5.3.27';
const BR='<br />';

function __construct(){
echo __FUNCTION__. self::BR;
echo __CLASS__. self::BR;
echo $this->Version. self::BR;

}

function test(){
echo __FUNCTION__. self::BR;
echo __CLASS__. self::BR;
echo $this->Version. self::BR;
}


}
$test=new test();

在我的记忆里第一种写法好像是析构冲突,但不确定暂且记下.

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!