以下代码是今天偶尔的一个想法:
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();
|
在我的记忆里第一种写法好像是析构冲突,但不确定暂且记下.