向大家请教PHP的类的问题,关于PHP的重载。
有下面一段很简单的代码。
<?php
class A{
var $name1="abc";
var $name2;
function A(){
$this->name2="";
}
function A($aa){
$this->name2=$aa;
}
function show(){
echo "show() is running.<br>";
echo "this->name1=".$this->name1."<br>";
echo "this->name2=".$this->name2."<br>";
}
}
$B=new A("123");
$B->show();
?>
在不同的系统上,有点可以运行,有的不行。
我在下面的几台机子上试过是可以运行的。配置如下。
A、redhat8.0 + Apache/2.0.40 + PHP/4.2.2
B、win2000 + Apache/1.3.22 + PHP/4.2.1
C、NT 4.0 +IIS/4.0 +PHP/4.0.6
运行得到如下的结果:
show() is running.
this->name1=abc
this->name2=123
而在下列一些系统上则不能运行。配置如下。
A、FreeBSD + Apache/1.3.28 + PHP/4.3.3
B、win2000 + Apache/1.3.28 + PHP/4.3.3 + Resin/3.0.3
C、win2000 + Apache/2.0.46 + PHP/4.3.3
D、win2000 + Apache/2.0.43 + PHP/4.3.2 + Tomcat/4.1
运行得到如下错误提示。
Fatal error: Cannot redeclare a() in D:\website\class.php on line 11
啊,想不通,为什么会是这样,这是什么道理,各位知道怎么解决吗?
这段代码在各位的系统上是否能运行,请告知系统配置情况(告知有分)。谢谢!
附:我的一个供大家试验的空间。
这是我的机子,只供大家验证,就是上面运行出错的B的配置,请不会攻击我的机子:
URL:http://icoming.vicp.net/
FTP:icoming.vicp.net
user:test
pass:test